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("http://www.ohloh.net:80") >>> signature_method_hmac_sha1 = oauth.OAuthSignatureMethod_HMAC_SHA1() >>> consumer = oauth.OAuthConsumer('myapikey', 'myoauthsecret') >>> oauth_request = oauth.OAuthRequest.from_consumer_and_token(consumer, http_url='http://www.ohloh.net/oauth/request_token') >>> oauth_request.sign_request(signature_method_hmac_sha1, consumer, None) >>> connection.request(oauth_request.http_method, 'http://www.ohloh.net/oauth/access_token', headers=oauth_request.to_header()) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.5/httplib.py", line 862, in request self._send_request(method, url, body, headers) File "/usr/lib/python2.5/httplib.py", line 885, in _send_request self.endheaders() File "/usr/lib/python2.5/httplib.py", line 856, in endheaders self._send_output() File "/usr/lib/python2.5/httplib.py", line 728, in _send_output self.send(msg) File "/usr/lib/python2.5/httplib.py", line 695, in send self.connect() File "/usr/lib/python2.5/httplib.py", line 663, in connect socket.SOCK_STREAM): socket.gaierror: (-2, 'Name or service not known') >>>
What I'm doing wrong and how to fix my error(s)?
Looks like you're missing a few things.
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 http://www.ohloh.net/oauth/request_token with oauthrequest.topostdata() as the body. The response would give you a request token.
Using the request token, you need to authorise the token. This requires opening a web browser at http://www.ohloh.net/oauth/authorize?oauth_token=XXXX (the request token you got in the previous step).
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 :(