Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issues with python version for python2.7 #43

Open
jingweiz opened this issue Feb 3, 2017 · 2 comments
Open

issues with python version for python2.7 #43

jingweiz opened this issue Feb 3, 2017 · 2 comments

Comments

@jingweiz
Copy link

jingweiz commented Feb 3, 2017

Hey,
I've been using the lua version of this package and it's awesome, really great work!
Now I'm trying out the python version, but am having this error:

>>> import display
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/zhang/.local/lib/python2.7/site-packages/display/__init__.py", line 5, in <module>
    import urllib.request
ImportError: No module named request

Then I found out that here urllib.request is a package for python3 but I'm using python2.7, so I modified the following lines of __init__.py:

# import urllib.request
import urllib2

# req = urllib.request.Request(URL, method='POST')
req = urllib2.Request(URL)

# resp = urllib.request.urlopen(req)
resp = urllib2.urlopen(req)

but then I get this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/me/.local/lib/python2.7/site-packages/display/__init__.py", line 76, in image
    'width': opts.get('width'),
  File "/home/me/.local/lib/python2.7/site-packages/display/__init__.py", line 38, in pane
    send(command='pane', type=panetype, id=win, title=title, content=content)
  File "/home/me/.local/lib/python2.7/site-packages/display/__init__.py", line 29, in send
    resp = urllib2.urlopen(req)
  File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 404, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 422, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 1214, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "/usr/lib/python2.7/urllib2.py", line 1184, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno 111] Connection refused>

So I guess I cannot just simply replace urllib.request.Request(URL, method='POST') also just to urllib2.Request(URL), so can you give me some ideas as how to modify the code to work under python2.7?

Thanks in advance!

@jingweiz
Copy link
Author

jingweiz commented Feb 5, 2017

So I actually find the solution to this problem.
Just have to run "th -ldisplay.start 8000 0.0.0.0" before you call display.image
Before in the lua version, the package will work without it, but here in the python version somehow this won't work. This would be an issue if I want to run my code for a relatively long period of time cos I found that the th -ldisplay.start breaks from time to time...
How should the code be modified to solve this issue?
Thanks!

@dimatura
Copy link

dimatura commented Mar 15, 2017

Hi @jingweiz, I have a modified python client that works in python2 (actually never tried it in python3). It is work in progress but I use it often. https://github.com/dimatura/pydisp, or pip install pydisp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants