【发布时间】:2020-04-01 08:50:50
【问题描述】:
我正在尝试使用 python 获取 xml 数据的课程,但即使我按照教程进行操作,我仍然收到 10054 错误。我做错了什么?
from bs4 import BeautifulSoup as soup
from urllib.request import urlopen
url = 'https://ehp.qld.gov.au/cgi-bin/air/xml.php?category=1®ion=ALL'
url_result = urlopen(url)
raw_data = url_result.read()
xml_soup = soup(raw_data, 'xml')
print(xml_soup)
这是我尝试运行代码时的错误。
ConnectionResetError Traceback (most recent call last)
<ipython-input-2-76e557f468e2> in <module>
1 url = 'https://apps.des.qld.gov.au/air-quality/xml/feed.php?category=1®ion=ALL'
----> 2 url_result = urlopen(url)
3 raw_data = url_result.read()
4 xml_soup = soup(raw_data, 'xml')
5 print(xml_soup)
~\anaconda3\lib\ssl.py in read(self, len, buffer)
927 try:
928 if buffer is not None:
--> 929 return self._sslobj.read(len, buffer)
930 else:
931 return self._sslobj.read(len)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
【问题讨论】:
-
表示主机已经关闭了你的连接。可能有很多原因,最可能的原因是您需要通过在请求中提供标头信息来欺骗用户代理。
-
我在 jupyterlab 中运行它,我正在遵循的教程显示了这个确切的代码和设置工作。
标签: python xml api beautifulsoup