运行空气质量计算案例5.0代码出现如下错误,请问怎么解决,谢谢!

import requests


def get_html_text(url):
    """
        返回url的文本
    """
    r = requests.get(url, timeout=30)
    print(r.status_code)
    return r.text


def main():
    """
        主函数
    """
    city_pinyin = input('请输入城市拼音:')
    url = 'http://pm25.in/' + city_pinyin
    url_text = get_html_text(url)
    print(url_text)


if __name__ == '__main__':
    main()
 
F:\pycharm\PycharmProjects\p1\venv\Scripts\python.exe F:/pycharm/PycharmProjects/p1/aqi_v5.0.py
请输入城市拼音:beijing
Traceback (most recent call last):
  File "F:\pycharm\PycharmProjects\p1\venv\lib\site-packages\urllib3\connection.py", line 159, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw)
  File "F:\pycharm\PycharmProjects\p1\venv\lib\site-packages\urllib3\util\connection.py", line 80, in create_connection
    raise err
  File "F:\pycharm\PycharmProjects\p1\venv\lib\site-packages\urllib3\util\connection.py", line 70, in create_connection
    sock.connect(sa)
TimeoutError: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "F:\pycharm\PycharmProjects\p1\venv\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "F:\pycharm\PycharmProjects\p1\venv\lib\site-packages\urllib3\connectionpool.py", line 354, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "F:\Anaconda\lib\http\client.py", line 1229, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "F:\Anaconda\lib\http\client.py", line 1275, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "F:\Anaconda\lib\http\client.py", line 1224, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "F:\Anaconda\lib\http\client.py", line 1016, in _send_output
    self.send(msg)
  File "F:\Anaconda\lib\http\client.py", line 956, in send
    self.connect()
  File "F:\pycharm\PycharmProjects\p1\venv\lib\site-packages\urllib3\connection.py", line 181, in connect
    conn = self._new_conn()
  File "F:\pycharm\PycharmProjects\p1\venv\lib\site-packages\urllib3\connection.py", line 168, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x000000A4AE1722B0>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "F:\pycharm\PycharmProjects\p1\venv\lib\site-packages\requests\adapters.py", line 449, in send
    timeout=timeout
  File "F:\pycharm\PycharmProjects\p1\venv\lib\site-packages\urllib3\connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "F:\pycharm\PycharmProjects\p1\venv\lib\site-packages\urllib3\util\retry.py", line 399, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='pm25.in', port=80): Max retries exceeded with url: /beijing (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000000A4AE1722B0>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "F:/pycharm/PycharmProjects/p1/aqi_v5.0.py", line 29, in <module>
    main()
  File "F:/pycharm/PycharmProjects/p1/aqi_v5.0.py", line 24, in main
    url_text = get_html_text(url)
  File "F:/pycharm/PycharmProjects/p1/aqi_v5.0.py", line 13, in get_html_text
    r = requests.get(url, timeout=30)
  File "F:\pycharm\PycharmProjects\p1\venv\lib\site-packages\requests\api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "F:\pycharm\PycharmProjects\p1\venv\lib\site-packages\requests\api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "F:\pycharm\PycharmProjects\p1\venv\lib\site-packages\requests\sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "F:\pycharm\PycharmProjects\p1\venv\lib\site-packages\requests\sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "F:\pycharm\PycharmProjects\p1\venv\lib\site-packages\requests\adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='pm25.in', port=80): Max retries exceeded with url: /beijing (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000000A4AE1722B0>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。'))

Process finished with exit code 1

要回复问题请先登录注册