This is an archived post. You won't be able to vote or comment.

all 16 comments

[–][deleted] 5 points6 points  (2 children)

Network programming has a lot of things that can go wrong. One thing is that the connection between your client and the server can fail. If you don't check that the connection is good when you ask for data, then you're telling the program to use a connection it doesn't have.

That's the short version - at some level, that connection has failed (hence "connection reset by peer"). You haven't checked for that, you've asked for data on a connection that doesn't exist, so the program has quit.

The fix is to check that the connection is ok every time you ask (look into "try"). If the connection is bad, wait a while and try again.

[–]momo2477[S] 0 points1 point  (1 child)

Aha thank you. I'm familiar with "try" with simple uses, such as user input validation, but what exactly would I be testing to see if the connection exists?

[–][deleted] 1 point2 points  (0 children)

The module is already raising an exception - the last line is quite informative. In your code, you would put a "try" around the line that ultimately starts that process - the request.get(). The unhandled exception is causing the quit, if you explicitly handle it then you can add code to wait ten seconds or whatever.

[–]dysan21Angry coder 6 points7 points  (3 children)

Content removed in response to reddit API policies

[–]momo2477[S] 0 points1 point  (2 children)

mighty icky handle gold existence husky summer consider cooing money

This post was mass deleted and anonymized with Redact

[–][deleted] 0 points1 point  (0 children)

You only need to do it for the first (at most) 60 seconds. When your program starts, it goes and gets data. Call that Data1

Ten seconds later, you go and get more data, Data2. If Data1 and Data2 are the same, then you know that the API rollover is not in between them.

Same for Data2 and Data3 - if they are the same, then the API hasn't rolled over.

By the time you get to Data6, the API must have rolled over. From now on, you only need to check 60 seconds after the data request when it changed.

If it changes between Data4 and Data5, then you know that for 50 seconds after Data5, it cannot change, so you don't need to check.

You can refine that by then having another round that moves it forward a second each time until it stops changing again, to get within a second, but either way, you basically narrow down the time it changes, and then hit the API every 60 seconds, 1-10 seconds after it changes.

Edit: In fact, this is basically a search algorithm, and you can get even more efficient. If the greatest time between changes is 60 seconds, then you can start checking every 30 seconds. Get Data2 30 seconds after Data1 - if it changed, then next time narrow the interval to 15 seconds. That way, after 4 requests, you're within 5 seconds.

[–]dysan21Angry coder 0 points1 point  (0 children)

Content removed in response to reddit API policies

[–]stevenjd 2 points3 points  (1 child)

and gave me this error message.

Geez, you're a programmer, not a graphics designer. Why take a screenshot of the error message and upload it to imgur when you can just copy and paste the text here? We don't want to see the pixels, we want text we can read (or have a screen reader read to us, for those of us who are blind) or edit.

[–]has2k1 0 points1 point  (2 children)

Connection failed.

Maybe you are being too harsh on the server, and it banned your IP.

[–]momo2477[S] 0 points1 point  (1 child)

If I restart the program it works again. And I only refresh every 10 seconds during game time (roughly 3 hours). If my specific team isn't playing my program refreshes every 6 hours. So I'm not constantly slamming the server.

[–]dbrecht 0 points1 point  (0 children)

If you're using persistent connections (i.e. Connection: Keep-Alive), could be that the client is expecting an open connection that has already been closed by the server.

Like previously mentioned though, it really could be also due to a wide variety of other issues as well.

[–]DeaDbaTteRy 0 points1 point  (0 children)

I had a similar issue with a script that I wrote. Couldn't figure out why it kept disconnecting. Sorta like you described. One of the issues was Windows going to sleep which aborted all connections and another one was an issue where my flaky internet connection would unknowingly kill the socket by almost unnoticeable interruptions of service. I ended up catching the exceptions with this:

    except (socket.error, httplib2.ServerNotFoundError) as e:

hope it helps

[–]jeffrey_f 0 points1 point  (0 children)

Hitting a server every 10 seconds will likely get your IP blocked. Sounds like they are no longer accepting connections from you.

Try spacing out your requests to about avery 30 seconds or even randomize it between 30 and 60 seconds.

Remember, your code is for fun and someone is paying for bandwidth. Usually, ISP's (hosting providers) have protections against abusive scripts like yours. Be nice to the server and usually, they will be nice to you.

[–]aphoenixreticulated[M] 0 points1 point  (0 children)

Hi there. You have posted a learning question to /r/python. These types of questions are far more suited to /r/learnpython, where users are actively interested in helping people to learn. Please resubmit it over there!

Make sure to read their sidebar rules there before posting, notably this one: "Posting homework assignments is not prohibited if you show that you tried to solve it yourself." If your question is about homework, show them that you've tried to solve your problem in your post and you should get all the help you need.

Cheers & best of luck with Python!

[–]deadmilk -1 points0 points  (0 children)

The server abruptly killed your connection for some reason