设为首页收藏本站

Crossin的编程教室

 找回密码
 立即加入
查看: 3857|回复: 2
打印 上一主题 下一主题

关于免费教程查天气2的问题

[复制链接]

2

主题

0

好友

22

积分

新手上路

Rank: 1

跳转到指定楼层
楼主
发表于 2024-1-15 13:47:57 来自手机 |只看该作者 |倒序浏览
代码是复制过去的,导入了requests库,有一堆报错栈。
/data/user/0/org.qpython.qpy/files/bin/qpython3.sh "/storage/emulated/0/Android/data/org.qpython.qpy/files/.py" && exit
/ $ /data/user/0/org.qpython.qpy/files/bin/
qpython3.sh "/storage/emulated/0/Android/da
ta/org.qpython.qpy/files/.py" && exit
请输入城市,回车退出:
北京
Traceback (most recent call last):
  File "/data/user/0/org.qpython.qpy/files/lib/python3.11/site-packages/urllib3/connection.py", line 203, in _new_conn
    sock = connection.create_connection(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/user/0/org.qpython.qpy/files/lib/python3.11/site-packages/urllib3/util/connection.py", line 60, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/user/0/org.qpython.qpy/files/lib/python3.11/socket.py", line 961, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
socket.gaierror: [Errno 7] No address associated with hostname

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/data/user/0/org.qpython.qpy/files/lib/python3.11/site-packages/urllib3/connectionpool.py", line 790, in urlopen
    response = self._make_request(
               ^^^^^^^^^^^^^^^^^^^
  File "/data/user/0/org.qpython.qpy/files/lib/python3.11/site-packages/urllib3/connectionpool.py", line 496, in _make_request
    conn.request(
  File "/data/user/0/org.qpython.qpy/files/lib/python3.11/site-packages/urllib3/connection.py", line 395, in request
    self.endheaders()
  File "/data/user/0/org.qpython.qpy/files/lib/python3.11/http/client.py", line 1277, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/data/user/0/org.qpython.qpy/files/lib/python3.11/http/client.py", line 1037, in _send_output
    self.send(msg)
  File "/data/user/0/org.qpython.qpy/files/lib/python3.11/http/client.py", line 975, in send
    self.connect()
  File "/data/user/0/org.qpython.qpy/files/lib/python3.11/site-packages/urllib3/connection.py", line 243, in connect
    self.sock = self._new_conn()
                ^^^^^^^^^^^^^^^^
  File "/data/user/0/org.qpython.qpy/files/lib/python3.11/site-packages/urllib3/connection.py", line 210, in _new_conn
    raise NameResolutionError(self.host, self, e) from e
urllib3.exceptions.NameResolutionError: <urllib3.connection.HTTPConnection object at 0x787357f790>: Failed to resolve 'wthrcdn.etouch.cn' ([Errno 7] No address associated with hostname)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/data/user/0/org.qpython.qpy/files/lib/python3.11/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "/data/user/0/org.qpython.qpy/files/lib/python3.11/site-packages/urllib3/connectionpool.py", line 844, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "/data/user/0/org.qpython.qpy/files/lib/python3.11/site-packages/urllib3/util/retry.py", line 515, in increment
    raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='wthrcdn.etouch.cn', port=80): Max retries exceeded with url: /weather_mini?city=%E5%8C%97%E4%BA%AC (Caused by NameResolutionError("<urllib3.connection.HTTPConnection object at 0x787357f790>: Failed to resolve 'wthrcdn.etouch.cn' ([Errno 7] No address associated with hostname)"))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/storage/emulated/0/Android/data/org.qpython.qpy/files/.py", line 6, in <module>
    req = requests.get('http://wthrcdn.etouch.cn/weather_mini?city=%s' % city)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/user/0/org.qpython.qpy/files/lib/python3.11/site-packages/requests/api.py", line 73, in get
    return request("get", url, params=params, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/user/0/org.qpython.qpy/files/lib/python3.11/site-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/user/0/org.qpython.qpy/files/lib/python3.11/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/user/0/org.qpython.qpy/files/lib/python3.11/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/user/0/org.qpython.qpy/files/lib/python3.11/site-packages/requests/adapters.py", line 519, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='wthrcdn.etouch.cn', port=80): Max retries exceeded with url: /weather_mini?city=%E5%8C%97%E4%BA%AC (Caused by NameResolutionError("<urllib3.connection.HTTPConnection object at 0x787357f790>: Failed to resolve 'wthrcdn.etouch.cn' ([Errno 7] No address associated with hostname)"))
/ $
回复

使用道具 举报

2

主题

0

好友

22

积分

新手上路

Rank: 1

沙发
发表于 2024-1-15 13:48:51 来自手机 |只看该作者
有大佬知道是什么问题吗?网站也这个网站我也无法访问。
回复

使用道具 举报

174

主题

45

好友

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

板凳
发表于 2024-1-15 23:57:22 |只看该作者
原接口无效了。

试试这个:
http://api.tangdouz.com/tq.php?dz=城市名

请求时需要加 user-agent

如果还是搞不定,只是练习网络请求的话,可以用这个接口来练习(结果无意义)
https://httpbin.org/get?city=城市
#==== Crossin的编程教室 ====#
微信ID:crossincode
网站:http://crossincode.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即加入

QQ|手机版|Archiver|Crossin的编程教室 ( 苏ICP备15063769号  

GMT+8, 2024-11-24 07:41 , Processed in 0.013501 second(s), 20 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部