Skip to content

Create a separate shift_planning.py version for Python3#4

Closed
gabeibarra wants to merge 2 commits into
tcp-software:masterfrom
gabeibarra:master
Closed

Create a separate shift_planning.py version for Python3#4
gabeibarra wants to merge 2 commits into
tcp-software:masterfrom
gabeibarra:master

Conversation

@gabeibarra
Copy link
Copy Markdown

Existing sdk works great in Python 2.7, but causes errors in Python 3.3 and 3.4. Here are updates that work in newer versions of Python.

Updated dependencies:
-urllib2 module is part of urllib in Python3. All modules needed in this script are found in urllib.request and urllib.parse

Updated "perform_request" function:
-urllib.urlencode -> urllib.parse.urlencode
-urllib2.Request -> urllib.request.Request
-urllib2.urlopen -> urllib.request.urlopen
-data needed to be encoded for "Post" method, so added binary_data variable.
-'.has_key()' not valid in Python3:
e.g. if response.has_key('error'): -> if 'error' in response:

Dependencies:
-urllib2 module is part of urllib in Python3. All modules needed in this script are found in urllib.request and urllib.parse

Updated "perform_request" function:
-urllib.urlencode -> urllib.parse.urlencode
-urllib2.Request -> urllib.request.Request
-urllib2.urlopen -> urllib.request.urlopen
-data needed to be encoded for "Post" method, so added binary_data variable.
-'.has_key()' not valid in Python3:
--if response.has_key('error'): -> if 'error' in response:
--if response.has_key('token'): -> if 'token' in response:
@gabeibarra gabeibarra changed the title Update shift_planning.py for Python3 Create a separate shift_planning.py version for Python3 Jun 5, 2015
@dutekvejin
Copy link
Copy Markdown

Hi @gabeibarra,
We can not change our master branch to work only with Python 3.3, so we can not merge your pull request. But it will be great to have SDK that will run on 2.7, 3.3 and 3.4 python versions. In order to achieve this you will have to make changes to your code to allow running SDK on multiple python versions.

We are lucky as urllib functions signatures are the same in 2.7 and 3.3. Doing something like this will do the job.

try:
    from urllib import urlencode  # py2
except ImportError:
    from urllib.parse import urlencode  # py3

I'm also sure that encoding post data in case of 3.3 also can be handled or maybe it will work encoded in both versions.

@gabeibarra gabeibarra closed this Aug 13, 2017
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

Successfully merging this pull request may close these issues.

2 participants