Skip to content

issues with python version for python2.7 #43

@jingweiz

Description

@jingweiz

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions