Create a separate shift_planning.py version for Python3#4
Closed
gabeibarra wants to merge 2 commits into
Closed
Conversation
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:
typo line 115
|
Hi @gabeibarra, 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 # py3I'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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: