Help with Python Requests

This is the place for queries that don't fit in any of the other categories.

Help with Python Requests

Postby sedavidw » Wed Feb 27, 2013 2:34 pm

I'm using get() from Python Requests to get JSON data from a server I have offsite. Some pseudo code is given below:

Code: Select all
for id in range(10):
someURL = "http://fakeURL" + str(id)
data = get(someURL).json()


I am constantly getting the following error (I've pulled out host and specific port information, I hope that isn't the problem):

ConnectionError: HTTPConnecctionPool(host ="host", port=port#). Max retries exceeded with url: caused by class 'socket.error'. A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host failed to respond.

At first I thought my requests were coming to fast so I put sleep lines in there to aid with that but I was still getting the error. Even if I run the code from the Python Shell I get it on the first try sometimes. However if I try to get the JSON data using my Chrome browser it works every time without issue. Which leads me to believe the offsite server is working fine. Any help is greatly appreciated
sedavidw
 
Posts: 4
Joined: Tue Feb 26, 2013 7:50 pm

Re: Help with Python Requests

Postby sedavidw » Wed Feb 27, 2013 6:27 pm

I have a "solution" that simply catches requests.exceptions.ConnectcionErrors when the queries are made. If an exception is thrown I just try again until no exception is thrown. This gets my algorithm through but if anyone knows a method of not getting the exceptions thrown I'd really appreciate it
sedavidw
 
Posts: 4
Joined: Tue Feb 26, 2013 7:50 pm


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 3 guests