连接错误:连接尝试失败,因为一段时间后被连接方未正确响应 [英] Connection Error: A connection attempt failed because the connected party did not properly respond after a period of time

查看:134
本文介绍了连接错误:连接尝试失败,因为一段时间后被连接方未正确响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用python开发一些利用Steam API的软件.我正在使用Flask运行和测试python代码.一切都进展顺利,但是现在我遇到了这个错误(我没有更改任何代码):

I'm developing some software in python that utilizes Steam APIs. I'm using Flask to run and test the python code. Everything was going swell, but now I'm getting this error (I haven't changed any code):

('连接异常终止.',错误(10060,'连接尝试失败因为关联方在一段时间后未正确响应时间,或建立的连接失败,因为连接的主机具有无法回应'))

('Connection aborted.', error(10060, 'A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond'))

我不知道为什么会出现此错误,因为代码运行得非常好,突然出现了错误,并且我没有更改代码,计算机或Flask中的任何内容.

I have no idea why this error is coming up, because the code was working perfectly fine and suddenly the error comes up, and I haven't changed anything in the code or with my computer or Flask.

代码:

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 have an explanation of what the error means, and why this is happening. Thanks in advance. I really appreciate the help.

推荐答案

好吧,这不是烧瓶错误,基本上是python套接字错误

Well, this is not the flask error, Its basically python socket error

由于10060似乎是超时错误,服务器是否很可能无法接受,并且如果网站在您的浏览器中打开,那么您的浏览器是否有更高的超时阈值?

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

尝试增加request.get()中的请求时间

try increasing 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 an expectation of incoming socket) - it is extremely rare that this would actually be a requirement to connect.

这篇关于连接错误:连接尝试失败,因为一段时间后被连接方未正确响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆