marians / openweather

Rudimentary python client for OpenWeatherMap.org
9 stars 4 forks source link

urllib.urlopen() throws Exception on Python 3.4. #5

Open johnjohndoe opened 9 years ago

johnjohndoe commented 9 years ago

I am trying to run the library on Windows 7 having Python 3.4. installed. I executed the script manually as follows:

$ python openweather.py -s 4885
OpenWeather.do_request() got unknown exception: <class 'AttributeError'> (1. attempt)
OpenWeather.do_request() got unknown exception: <class 'AttributeError'> (2. attempt)
OpenWeather.do_request() got unknown exception: <class 'AttributeError'> (3. attempt)
Traceback (most recent call last):
  File "D:\Wetter\openweather.py", line 235, in <module>
    main()
  File "D:\Wetter\openweather.py", line 232, in main
    print(json.dumps(flatten_dict(weather), indent=4, sort_keys=True))
  File "D:\Wetter\openweather.py", line 154, in flatten_dict
    for k, v in d.items():
AttributeError: 'NoneType' object has no attribute 'items'

From what I could find out there are version issues with urllib being using in line 132. Here is what I found:

Note: The urllib2 module has been split across several modules in Python 3 named urllib.request and urllib.error. The 2to3 tool will automatically adapt imports when converting your sources to Python 3.

Source


This seems to be a problem with Python 3.4, the script basically works with Python 2.7.8 - see issue #6. Please note in the README.md that people should use Python 2.7.x.

marians commented 9 years ago

Added the note to the README as you suggested. Will leave the tiket open as an inspiration for contributors. :)

johnjohndoe commented 9 years ago

@ptrv In case you worked with urllib* before ... maybe you want to provide a fix here.