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

Python3 v0.11.0 socks.py NameError: name 'basestring' is not defined #100

Closed
wants to merge 2 commits into from

Conversation

uu4k
Copy link
Contributor

@uu4k uu4k commented Mar 28, 2018

Dear Httplib2 team,

I'm creating tools for gcp with Google API Python Client Library.

I get errors tring to run sample code, and I detect a httplib2 bug for python3.

Traceback (most recent call last):
  File "sample.py", line 10, in <module>
    main()
  File "sample.py", line 5, in main
    compute = googleapiclient.discovery.build('compute', 'v1')
  File "/Users/xxxxxx/PycharmProjects/gcptools/venv/lib/python3.6/site-packages/oauth2client/_helpers.py", line 133, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/Users/xxxxxx/PycharmProjects/gcptools/venv/lib/python3.6/site-packages/googleapiclient/discovery.py", line 229, in build
    requested_url, discovery_http, cache_discovery, cache)
  File "/Users/xxxxxx/PycharmProjects/gcptools/venv/lib/python3.6/site-packages/googleapiclient/discovery.py", line 276, in _retrieve_discovery_doc
    resp, content = http.request(actual_url)
  File "/Users/xxxxxx/PycharmProjects/gcptools/venv/lib/python3.6/site-packages/httplib2/__init__.py", line 1509, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/Users/xxxxxx/PycharmProjects/gcptools/venv/lib/python3.6/site-packages/httplib2/__init__.py", line 1259, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/Users/xxxxxx/PycharmProjects/gcptools/venv/lib/python3.6/site-packages/httplib2/__init__.py", line 1182, in _conn_request
    conn.connect()
  File "/Users/xxxxxx/PycharmProjects/gcptools/venv/lib/python3.6/site-packages/httplib2/__init__.py", line 1006, in connect
    sock.connect((self.host, self.port))
  File "/Users/xxxxxx/PycharmProjects/gcptools/venv/lib/python3.6/site-packages/httplib2/socks.py", line 412, in connect
    if (not type(destpair) in (list,tuple)) or (len(destpair) < 2) or (not isinstance(destpair[0], basestring)) or (type(destpair[1]) != int):
NameError: name 'basestring' is not defined

The builtin basestring abstract type was removed on Python3, so I'd like replace basestring with str.

Thanks.

@codecov
Copy link

codecov bot commented Mar 28, 2018

Codecov Report

Merging #100 into master will increase coverage by 1.8%.
The diff coverage is 60%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #100     +/-   ##
=========================================
+ Coverage   68.58%   70.38%   +1.8%     
=========================================
  Files           6        6             
  Lines        2454     2458      +4     
=========================================
+ Hits         1683     1730     +47     
+ Misses        771      728     -43
Impacted Files Coverage Δ
python3/httplib2/socks.py 22.07% <100%> (+6.06%) ⬆️
python2/httplib2/__init__.py 81.8% <50%> (+0.84%) ⬆️
python3/httplib2/__init__.py 82.91% <50%> (+0.8%) ⬆️
python2/httplib2/socks.py 22.07% <0%> (+6.06%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f20cd36...aedc4a7. Read the comment docs.

@temoto temoto changed the title Python3 v0.110 NameError: name 'basestring' is not defined Python3 v0.11.0 socks.py NameError: name 'basestring' is not defined Mar 28, 2018
temoto added a commit that referenced this pull request Mar 28, 2018
@temoto
Copy link
Member

temoto commented Mar 28, 2018

I've added test here 2f59ff9 please include it in PR to keep authorship or else I will squash commits.

@temoto temoto self-requested a review March 28, 2018 15:42
@temoto
Copy link
Member

temoto commented Mar 28, 2018

@uu4k update: no action required, we wait for review.

Turns out I can push into your master, all this privacy buzz has some substance after all.

Copy link
Contributor

@stinky2nine stinky2nine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

temoto pushed a commit that referenced this pull request Mar 29, 2018
@temoto
Copy link
Member

temoto commented Mar 29, 2018

Merged in a49b5a9

Thank you @uu4k

@temoto temoto closed this Mar 29, 2018
@temoto
Copy link
Member

temoto commented Mar 30, 2018

Fix is released on PyPI v0.11.3

@@ -409,7 +409,7 @@ def connect(self, destpair):
To select the proxy server use setproxy().
"""
# Do a minimal input check first
if (not type(destpair) in (list,tuple)) or (len(destpair) < 2) or (not isinstance(destpair[0], basestring)) or (type(destpair[1]) != int):
if (not type(destpair) in (list,tuple)) or (len(destpair) < 2) or (not isinstance(destpair[0], str)) or (type(destpair[1]) != int):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This modification changes the test is type(destpair[0]) is unicode on Python 2. Is that situation possible? The normal fix for this is to define basestring in Python 3.

try:
    basestring        # Python 2
except NameError:
    basestring = str  # Python 3

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

Successfully merging this pull request may close these issues.

None yet

4 participants