Forums

requests.post error

Hi, I am using the requests module to access the rest api of IronWorker. The code works from local machine, but gives the following error in pythonanywhere:

ERROR The requested URL could not be retrieved The following error was encountered while trying to retrieve the URL: https://worker-aws-us-east-1.iron.io/2/projects/5225ee865fc8c50005000003/tasks Unsupported Request Method and Protocol Squid does not support all request methods for all access protocols. For example, you can not POST a Gopher request.

I checked the whitelist, and .iron.io is indeed in the list. I've seen mentioned that requests module might have a bug that's to do with urllib3, is this it? If so, how do I override it? I have a free account.

My code (the oath token is deleted):

url = "https://worker-aws-us-east-1.iron.io/2/projects/5225ee865fc8c50005000003/tasks"
payload = {'tasks' : [{'code_name':'try','payload':'{"var1": "val1"}'}] }
headers = { 'Content-Type' : 'application/json',
        'Accept' : 'application/json',
        'Accept-Encoding' : 'gzip/deflate',
        'Authorization' : 'OAuth x*****************4' }

logger.info("Queueing worker with payload: "+str(payload))
response = requests.post(url,data=simplejson.dumps(payload),headers=headers)

Thanks, Jonathan.

Hi Jonathan -- yes, that does look like the requests bug. We've had reports that the next release of requests will fix it, but in the meantime I think your best best would be to use a different HTTP library (pycurl works, I believe, though its syntax isn't quite as elegant as requests [to say the least]). Or, of course you could upgrade to a Hacker account :-)

Thanks. If this is a bug in the requests module, how does upgrading the account help?

Free accounts can only access the Internet through a proxy, which (as you know) we use to limit access to specific sites. This is an anti-hacker thing -- before we did it, a number of people were using us as a launching post for attacks on other sites.

Paid accounts have direct, unproxied Internet access because if they do something they shouldn't, they're easily identifiable IRL -- which puts most hackers and spammers off. And the requests bug only affects connections made through the proxy.

I understand.

Thanks.

...and thanks for upgrading :-)