ox-it / requests-negotiate

GSSAPI auth support for Python's requests library
BSD 3-Clause "New" or "Revised" License
4 stars 4 forks source link

minor fix #7

Closed oucsaw closed 8 years ago

oucsaw commented 8 years ago

minor tweak to use underlying socket class, not WrappedSocket (which has no getpeername)

alexdutton commented 8 years ago

Curious. It worked for me with requests==2.10.0, where response.raw._connection.sock is a ssl.SSLSocket. Did it not work at all for you?

oucsaw commented 8 years ago

File "/srv/silver/local/lib/python2.7/site-packages/requests_negotiate/init.py", line 28, in get_hostname return socket.gethostbyaddr(response.raw._connection.sock.getpeername()[0])[0] AttributeError: 'WrappedSocket' object has no attribute 'getpeername'

oucsaw commented 8 years ago

.. and requests seems to be 2.10.0 (using python 2.7)

alexdutton commented 8 years ago

Are you using it over SSL? (silly question, but best to check)

answers his own question (yes)

oucsaw commented 8 years ago

Yes:

auth_token = requests_negotiate.HTTPNegotiateAuth()
url = 'https://server.ox.ac.uk/'
api = slumber.API(url,auth=auth_token)
api.person.get(q='%s:%s' % (lookup_query, lookup_key), format='json')

Will try to reproduce without the slumber module ...

alexdutton commented 8 years ago

I think that if you've got pyopenssl support available (i.e. requests.packages.urllib3.contrib.pyopenssl doesn't raise an ImportError) it'll use that for preference over the builtin ssl module, and that monkey-patches to use WrappedSocket.

alexdutton commented 8 years ago

I'm going to merge this and then tweak again to handle both cases.