gpt4 book ai didi

python - 连接错误 : A connection attempt failed because the connected party did not properly respond after a period of time

转载 作者:太空狗 更新时间:2023-10-30 02:10:49 25 4
gpt4 key购买 nike

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

('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。

代码:

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)

我想解释错误的含义以及发生这种情况的原因。提前致谢。非常感谢您的帮助。

最佳答案

嗯,这不是 flask 错误,它基本上是 python 套接字错误

10060好像是超时错误,有没有可能是服务器接受和处理的很慢如果网站在您的浏览器中打开,那么您的浏览器是否有可能具有更高的超时阈值?

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

如果远程服务器也在您的访问范围内,那么:您不需要绑定(bind)套接字(除非远程服务器期望传入套接字)- 这实际上是连接要求的情况极为罕见。

关于python - 连接错误 : A connection attempt failed because the connected party did not properly respond after a period of time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26700211/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com