1

per the example in the httplib docs:

>>> import httplib, urllib
>>> params = urllib.urlencode({'@number': 12524, '@type': 'issue', '@action': 'show'})
>>> headers = {"Content-type": "application/x-www-form-urlencoded",
...            "Accept": "text/plain"}
>>> conn = httplib.HTTPConnection("bugs.python.org")
>>> conn.request("POST", "", params, headers)
>>> response = conn.getresponse()
>>> print response.status, response.reason
302 Found
>>> data = response.read()
>>> data
'Redirecting to <a href="http://bugs.python.org/issue12524">http://bugs.python.org/issue12524</a>'
>>> conn.close()

my code is:

import httplib
import urllib

token = request.POST.get('token')
if token:
    params = urllib.urlencode({'apiKey':'[some string]', 'token':token})
    connection = httplib.HTTPSConnection('rpxnow.com/api/v2/auth_info')
    connection.request('POST', "", params)
    response = connection.getresponse()
    print response.read()

inspection of my local vars yeilds:

connection: "httplib.HTTPSConnection instance at 0x8baa4ac" params: 'token=[some string]&apiKey=[some string]'

(My instructions to make this call are:

Use the token to make the auth_info API call: URL: https://rpxnow.com/api/v2/auth_info Parameters:

apiKey [some string] token The token value you extracted above)

but I'm getting the error mentioned in the subject line. Why?

Colleen
  • 23,899
  • 12
  • 45
  • 75

3 Answers3

4

You've misunderstood the documentation to httplib. The parameter to instantiate the HTTPSConnection is just the hostname. You then pass the actual path as the second param to request. So:

connection = httplib.HTTPSConnection('rpxnow.com')
connection.request('POST', '/api/v2/auth_info', params)
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
0

I don't know what rpxnow.com is and I am not familiar with their API, but this error message indicates that they do not have a service responding to requests at that URL (i.e. 'rpxnow.com/api/v2/auth_info').

Are you able to verify that their service is up and running at that URL?

sclaughl
  • 26
  • 2
  • it appears to be, as when I go there I get: {"err":{"msg":"Missing parameter: apiKey","code":0},"stat":"fail"} (I'm assuming if the service was down I would get a different message) – Colleen Dec 28 '11 at 22:07
0

Try using this:

http://docs.python-requests.org/en/latest/user/quickstart/#make-a-post-request

import requests

payload = {'apiKey':'somevalue', 'token':'some_token'}
r = requests.post('https://rpxnow.com/api/v2/auth_info', data=payload)
r.content
joemar.ct
  • 1,206
  • 9
  • 14
Saurav
  • 3,096
  • 3
  • 19
  • 12