用yweather进行简单测试就失败了

时间:2017-09-21 20:51:39

标签: python

这是我的代码:

import yweather

client = yweather.Client()
id = client.fetch_woeid("Beijing, China")
beijing_weather = client.fetch_weather(id)

很好很简单......出于yweather的文档,我收到了一个错误:

> Traceback (most recent call last):
  File "C:\Users\DSHenderson\AppData\Local\Programs\Python\Python36\lib\urllib\request.py", line 1318, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File "C:\Users\DSHenderson\AppData\Local\Programs\Python\Python36\lib\http\client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Users\DSHenderson\AppData\Local\Programs\Python\Python36\lib\http\client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Users\DSHenderson\AppData\Local\Programs\Python\Python36\lib\http\client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Users\DSHenderson\AppData\Local\Programs\Python\Python36\lib\http\client.py", line 1026, in _send_output
    self.send(msg)
  File "C:\Users\DSHenderson\AppData\Local\Programs\Python\Python36\lib\http\client.py", line 964, in send
    self.connect()
  File "C:\Users\DSHenderson\AppData\Local\Programs\Python\Python36\lib\http\client.py", line 936, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "C:\Users\DSHenderson\AppData\Local\Programs\Python\Python36\lib\socket.py", line 704, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "C:\Users\DSHenderson\AppData\Local\Programs\Python\Python36\lib\socket.py", line 743, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):   File
> "C:/Users/DSHenderson/PycharmProjects/WeatherAPI/Main.py", line 4, in
> <module>
>     beijing_weather = client.fetch_weather(id)   File "C:\Users\DSHenderson\AppData\Local\Programs\Python\Python36\lib\site-packages\yweather.py",
> line 180, in fetch_weather
>     rss = self._fetch_xml(url)   File "C:\Users\DSHenderson\AppData\Local\Programs\Python\Python36\lib\site-packages\yweather.py",
> line 344, in _fetch_xml
>     with contextlib.closing(urlopen(url)) as f:   File "C:\Users\DSHenderson\AppData\Local\Programs\Python\Python36\lib\urllib\request.py",
> line 223, in urlopen
>     return opener.open(url, data, timeout)   File "C:\Users\DSHenderson\AppData\Local\Programs\Python\Python36\lib\urllib\request.py",
> line 526, in open
>     response = self._open(req, data)   File "C:\Users\DSHenderson\AppData\Local\Programs\Python\Python36\lib\urllib\request.py",
> line 544, in _open
>     '_open', req)   File "C:\Users\DSHenderson\AppData\Local\Programs\Python\Python36\lib\urllib\request.py",
> line 504, in _call_chain
>     result = func(*args)   File "C:\Users\DSHenderson\AppData\Local\Programs\Python\Python36\lib\urllib\request.py",
> line 1346, in http_open
>     return self.do_open(http.client.HTTPConnection, req)   File "C:\Users\DSHenderson\AppData\Local\Programs\Python\Python36\lib\urllib\request.py",
> line 1320, in do_open
>     raise URLError(err) urllib.error.URLError: <urlopen error [Errno 11001] getaddrinfo failed>

那令人沮丧。有什么想法吗?

编辑:将追溯转换为&#34;代码&#34;为了便于阅读。

Edit2:现在使用forecastiopy,似乎以同样的方式完成工作。

0 个答案:

没有答案