Connection Error: The connection attempt failed because the related party did not respond properly after a while

I am developing some python software that uses the Steam API. I am using Flask to run and inspect python code. Everything was going, but now I get this error (I haven't changed the code):

('The connection has been interrupted.', Error (10060, "The connection attempt could not be made because the related party did not respond properly after a period of time or the connection was established because the connected host could not answer"))

I have no idea why this error occurs because the code is working fine and suddenly an error occurs and I haven't changed anything in the code or with my computer or Flask.

Code:

import urllib
import itertools
import urllib2
import time
from datetime import datetime
from bs4 import BeautifulSoup
from flask import Flask
import requests
import json
import xml.etree.ElementTree as ET
from xml.dom.minidom import parseString
import sys


app = Flask(__name__)
API_KEY = 'XXX'
API_BASEURL = 'http://api.steampowered.com/'
API_GET_FRIENDS = API_BASEURL + 'ISteamUser/GetFriendList/v0001/?key='+API_KEY+'&steamid='
API_GET_SUMMARIES = API_BASEURL + 'ISteamUser/GetPlayerSummaries/v0002/?key='+API_KEY+'&steamids='
PROFILE_URL = 'http://steamcommunity.com/profiles/'
steamIDs = []
myFriends = []

class steamUser:
    def __init__(self, name, steamid, isPhisher):
        self.name = name
        self.steamid = steamid
        self.isPhisher = isPhisher

    def setPhisherStatus(self, phisher):
        self.isPhisher = phisher

@app.route('/DeterminePhisher/<steamid>')
def getFriendList(steamid):
    try:
        r = requests.get(API_GET_FRIENDS+steamid)
        data = r.json()
        for friend in data['friendslist']['friends']:
            steamIDs.append(friend['steamid'])
        return isPhisher(steamIDs)
    except requests.exceptions.ConnectionError as e:
        return str(e.message)

def isPhisher(ids):
    phisherusers = ''
    for l in chunksiter(ids, 50):
        sids = ','.join(map(str, l))
        try:
            r = requests.get(API_GET_SUMMARIES+sids)
            data = r.json();
            for i in range(len(data['response']['players'])):
                steamFriend = data['response']['players'][i]
                n = steamUser(steamFriend['personaname'], steamFriend['steamid'], False)
                if steamFriend['communityvisibilitystate'] and not steamFriend['personastate']:
                    url =  PROFILE_URL+steamFriend['steamid']+'?xml=1'
                    dat = requests.get(url)
                    if 'profilestate' not in steamFriend:
                        n.setPhisherStatus(True);
                        phisherusers = (phisherusers + ('%s is a phisher' % n.name) + ', ')
                    if parseString(dat.text.encode('utf8')).getElementsByTagName('privacyState'):
                        privacy = str(parseString(dat.text.encode('utf-8')).getElementsByTagName('privacyState')[0].firstChild.wholeText)
                        if (privacy == 'private'):
                            n.setPhisherStatus(True)
                            phisherusers = (phisherusers + ('%s is a phisher' % n.name) + ', ')
                elif 'profilestate' not in steamFriend:
                    n.setPhisherStatus(True);
                    phisherusers = (phisherusers + ('%s is a phisher' % n.name) + ', ')
                else:
                    steamprofile = BeautifulSoup(urllib.urlopen(PROFILE_URL+steamFriend['steamid']).read())
                    for row in steamprofile('div', {'class': 'commentthread_comment  '}):
                        comment = row.find_all('div', 'commentthread_comment_text')[0].get_text().lower()
                        if ('phisher' in comment) or ('scammer' in comment):
                            n.setPhisherStatus(True)
                            phisherusers = (phisherusers + ('%s is a phisher' % n.name) + ', ')
                myFriends.append(n);
        except requests.exceptions.ConnectionError as e:
            return str(e.message)
        except:
            return "Unexpected error:", sys.exc_info()[0]
    return phisherusers

def chunksiter(l, chunks):
    i,j,n = 0,0,0
    rl = []
    while n < len(l)/chunks:        
        rl.append(l[i:j+chunks])        
        i+=chunks
        j+=j+chunks        
        n+=1
    return iter(rl)

app.run(debug=True)

      

I would like to get an explanation of what the error means and why it is happening. Thank you in advance. I really appreciate the help.

+3


source to share


3 answers


Well this is not a flash drive bug, its bug is basically python socket

since 10060 seems to be a timeout error, is it possible that the server is very slow in accepting and if the website opens in your browser, then is it likely that your browser has a higher timeout threshold?



try increasing the request time in request.get ()

if the remote server is also under your access, then: You don't need to bind the socket (unless the remote server has expectations for an incoming socket) - it's very rare that this is actually a requirement for a connection.

+5


source


I think it is because the steam server is unstable or some kind of internet problem.

Generally, you cannot fix the mesh. Still, some methods can help you.



First, when you catch a network error, you let your thread sleep for one second, then try again!

Second, I suggest using Flask-Cache to do this, for example cache 60 seconds, it will help you reduce the HTTP request.

+2


source


In my experience, "the related party did not respond after a while", especially when the same code worked before, is usually related to MTU sizes. Usually you need to determine the maximum MTU size (remember to add 28 bytes as described in the link) and then you can change the MTU size on your client machine.

0


source







All Articles