获取连接异常终止,Python中的远程断开连接错误

时间:2018-10-11 08:48:44

标签: python

from bs4 import BeautifulSoup

import requests

url = "http://www.ticketcity.com/kansas-city-tickets/arrowhead-stadium-tickets/arizona-cardinals-at-kansas-city-chiefs-nov-11-2018-2653648.html"

headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 6.0; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0' }

html = requests.get(url, headers = headers)
  

ConnectionError :(“连接已中止。”,RemoteDisconnected(“远程   结束无响应的关闭连接',))

任何人都可以帮助解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

您的参数不匹配。通过删除秒headers来解决此问题:

In [48]: from bs4 import BeautifulSoup
    ...: 
    ...: import requests
    ...: 
    ...: url = "http://www.ticketcity.com/kansas-city-tickets/arrowhead-stadium-tickets/arizona-cardinals-at-kansas-city-chiefs-nov-11-2018-2653648.html"
    ...: 
    ...: headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 6.0; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0' }
    ...: 
    ...: html = requests.get(url, headers)
    ...: 
    ...: 


In [49]: 

In [49]: html.status_code
Out[49]: 200