Forums : Ohloh API Discussion

OAuth and Python - no luck

Hello All!
I'm trying to access ohloh wia python-oauth library, but failed miserably:

[petro@Sulaco ohloh]$ python
Python 2.5.1 (r251:54863, Jun 15 2008, 18:27:49) 
[GCC 4.3.0 20080428 (Red Hat 4.3.0-8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import oauth
>>> import httplib
>>> connection = httplib.HTTPConnection("")
>>> signature_method_hmac_sha1 = oauth.OAuthSignatureMethod_HMAC_SHA1()
>>> consumer = oauth.OAuthConsumer('myapikey', 'myoauthsecret')
>>> oauth_request = oauth.OAuthRequest.from_consumer_and_token(consumer, http_url='')
>>> oauth_request.sign_request(signature_method_hmac_sha1, consumer, None)
>>> connection.request(oauth_request.http_method, '', headers=oauth_request.to_header())
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.5/", line 862, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python2.5/", line 885, in _send_request
  File "/usr/lib/python2.5/", line 856, in endheaders
  File "/usr/lib/python2.5/", line 728, in _send_output
  File "/usr/lib/python2.5/", line 695, in send
  File "/usr/lib/python2.5/", line 663, in connect
socket.gaierror: (-2, 'Name or service not known')

What I'm doing wrong and how to fix my error(s)?

Peter Lemenkov over 9 years ago

Looks like you're missing a few things.

  1. after creating the OAuthRequest for the /oauth/request URL and signing it, you need to make a request to that URL. This would be a POST request to with oauthrequest.topostdata() as the body. The response would give you a request token.

  2. Using the request token, you need to authorise the token. This requires opening a web browser at (the request token you got in the previous step).

  3. Once you've authorised the token, make a request to the .../access_token URL, passing in the request token. This is done in almost the same way as in (1). When you do this request, you'll exchange the request token for an access token that you can use to access the API.

The Python oauth library isn't that great, so it is pretty easy to make mistakes like this :(

James Henstridge about 9 years ago

Post a Response