Skip to content
This repository was archived by the owner on Jun 11, 2020. It is now read-only.

Support python3 #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Support python3 #6

wants to merge 3 commits into from

Conversation

maxhutch
Copy link

Here's a bunch of "translation". Python2.7 seems to still be working fine. I've run into a non-trivial issue in Python3. I can authenticate, but issuing any real calls leads to an error buried in sockets. Any suggestions?

maxhutch@edoras:~/src/transfer-api-client-python$ ~/anaconda3/bin/python -i -m globusonline.transfer.api_client.main maxhutch -p
Globus Online Password: 
>>> api.task_list()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/maxhutch/src/transfer-api-client-python/globusonline/transfer/api_client/__init__.py", line 387, in task_list
    return self.get("/task_list" + encode_qs(kw))
  File "/home/maxhutch/src/transfer-api-client-python/globusonline/transfer/api_client/__init__.py", line 347, in get
    return self._request_json("GET", path)
  File "/home/maxhutch/src/transfer-api-client-python/globusonline/transfer/api_client/__init__.py", line 323, in _request_json
    r, response_body = self._request(method, path, body, content_type)
  File "/home/maxhutch/src/transfer-api-client-python/globusonline/transfer/api_client/__init__.py", line 267, in _request
    r, response_body = do_request()
  File "/home/maxhutch/src/transfer-api-client-python/globusonline/transfer/api_client/__init__.py", line 258, in do_request
    self.c.request(method, url, body=body, headers=headers)
  File "/home/maxhutch/anaconda3/lib/python3.4/http/client.py", line 1090, in request
    self._send_request(method, url, body, headers)
  File "/home/maxhutch/anaconda3/lib/python3.4/http/client.py", line 1128, in _send_request
    self.endheaders(body)
  File "/home/maxhutch/anaconda3/lib/python3.4/http/client.py", line 1086, in endheaders
    self._send_output(message_body)
  File "/home/maxhutch/anaconda3/lib/python3.4/http/client.py", line 924, in _send_output
    self.send(msg)
  File "/home/maxhutch/anaconda3/lib/python3.4/http/client.py", line 859, in send
    self.connect()
  File "/home/maxhutch/src/transfer-api-client-python/globusonline/transfer/api_client/verified_https.py", line 97, in connect
    sock = socket.create_connection((self.host, self.port), self.timeout)
  File "/home/maxhutch/anaconda3/lib/python3.4/socket.py", line 509, in create_connection
    raise err
  File "/home/maxhutch/anaconda3/lib/python3.4/socket.py", line 500, in create_connection
    sock.connect(sa)
BlockingIOError: [Errno 115] Operation now in progress

I've done three things:
 1. Replaced print with print(), imported from __future__
 2. Wrapped python2-only libraries in try,except with their python3
 equivalents
 3. Replaced xrange with range, which in Python3 defaults to xrange-like
 functionality.  In all cases, the size of the expclicit list is either
 small (e.g. xrange(5) or xrange(self.max_attempts) or small compared to
 the other data (self.index_map).
@bd4
Copy link
Contributor

bd4 commented Mar 24, 2015

The verified_https code relies on internals (non-public api) which probably changed in 3.x. It looks like 3.4 has better built-in support for verifying peer certificates, but not sure about earlier 3.x. It will probably be a pain to make verified _https support a wider range of versions, but not impossible. This is one of the biggest failings of the Python standard library, we shouldn't have to go through major hoops just to get not broken https, I can't believe it took until 3.4.

Another direction would be to use a third party library like requests, but I really want Transfer API lib to work out of the box with Python standard lib.

@bd4
Copy link
Contributor

bd4 commented Mar 24, 2015

Before spending time on verified_https, I would sub the standard lib HTTPSConnection back in(don't use verified_https at all) and see if it works in Python3. My guess is that it will work and the problem really is in verified_https, but it's possible there is a more subtle change in how the httplib works that is causing it to break.

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

Successfully merging this pull request may close these issues.

2 participants