Wttr.in: Python 3 support

Created on 25 Oct 2019  路  9Comments  路  Source: chubin/wttr.in

wttr.in still uses python 2.

Code syntax is compatible with python 3, but there are several string/Unicode-related
issue in the code, like this:

[root@xyz wttr.in]# ve/bin/python bin/srv.py
Traceback (most recent call last):
  File "bin/srv.py", line 20, in <module>
    import wttr_srv
  File "/root/wttr.in/lib/wttr_srv.py", line 23, in <module>
    from location import is_location_blocked, location_processing
  File "/root/wttr.in/lib/location.py", line 185, in <module>
    LOCATION_ALIAS = load_aliases(ALIASES)
  File "/root/wttr.in/lib/location.py", line 171, in load_aliases
    from_, to_ = line.decode('utf-8').split(':', 1)
AttributeError: 'str' object has no attribute 'decode'
bug work-started

Most helpful comment

Now Python 3 is fully supported and should be used to run wttr.in.
Python 2 is out of support now

All 9 comments

@arkylin Are you using python 2 or python 3?

I tried both python2 and python3

Python 3.7.5
[root@c07535057b92 wttr.in]# ve/bin/python bin/srv.py
Traceback (most recent call last):
File "bin/srv.py", line 20, in
import wttr_srv
File "/root/wttr.in/lib/wttr_srv.py", line 23, in
from location import is_location_blocked, location_processing
File "/root/wttr.in/lib/location.py", line 185, in
LOCATION_ALIAS = load_aliases(ALIASES)
File "/root/wttr.in/lib/location.py", line 171, in load_aliases
from_, to_ = line.decode('utf-8').split(':', 1)
AttributeError: 'str' object has no attribute 'decode'

Python 2.7
There will always be one or two requirements in python2 that cannot be installed
Collecting timezonefinder
Using cached https://files.pythonhosted.org/packages/3c/a1/544681d5a58cd0a80ac914d81f983cdd3a07d4791789a29f26e329033e3c/timezonefinder-4.2.0.tar.gz
ERROR: Command errored out with exit status 1:
command: /root/wttr.in/env2.7/bin/python2.7 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-kFuZys/timezonefinder/setup.py'"'"'; __file__='"'"'/tmp/pip-install-kFuZys/timezonefinder/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-kFuZys/timezonefinder/pip-egg-info
cwd: /tmp/pip-install-kFuZys/timezonefinder/
Complete output (10 lines):
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-install-kFuZys/timezonefinder/setup.py", line 7, in
from timezonefinder.global_settings import DATA_FILE_NAMES
File "timezonefinder/__init__.py", line 2, in
from .timezonefinder import TimezoneFinder
File "timezonefinder/timezonefinder.py", line 276
def closest_timezone_at(self, *, lat, lng, delta_degree=1, exact_computation=False, return_distances=False,
^
SyntaxError: invalid syntax
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

[root@c07535057b92 wttr.in]# env2.7/bin/python bin/srv.py
Traceback (most recent call last):
File "bin/srv.py", line 4, in
from gevent.pywsgi import WSGIServer
ImportError: No module named gevent.pywsgi

I have a suggestion: I hope you can put geolite2-city.mmdb in the data directory

Hello,
I have the same issue with python 3.7.3 :(

Traceback (most recent call last):
File "bin/srv.py", line 20, in
import wttr_srv
File "/home/user/wttr.in/lib/wttr_srv.py", line 23, in
from location import is_location_blocked, location_processing
File "/home/user/wttr.in/lib/location.py", line 185, in
LOCATION_ALIAS = load_aliases(ALIASES)
File "/home/user/wttr.in/lib/location.py", line 171, in load_aliases
from_, to_ = line.decode('utf-8').split(':', 1)
AttributeError: 'str' object has no attribute 'decode'

Thank you

wttr.in is compatible with python 3.7.x ?

@caywin25 It is not fully compatible. In https://github.com/chubin/wttr.in/commit/e5ab61dea31d863d4b280d08bc57a1d32c269bae, I've added several workarounds, so it at least starts, but some of the dependencies does no support python3, so several features are not running with python 3 at the moment (all related to v2 and one-line mode).

@chubin , thx for your reply and fix code.
wttr.in server is running, but now I have this issue in wttr.in log when I want to test wttr.in in my browser :

Traceback (most recent call last):
  File "/home/user/wttr.in/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/user/wttr.in/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/user/wttr.in/lib/python3.7/site-packages/flask/app.py", line 1820, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/user/wttr.in/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/home/user/wttr.in/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/user/wttr.in/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "bin/srv.py", line 51, in wttr
    return wttr_srv.wttr(location, request)
  File "/home/user/wttr.in/lib/wttr_srv.py", line 235, in wttr
    location_processing(location, ip_addr)
  File "/home/user/wttr.in/lib/location.py", line 236, in location_processing
    if is_ip(location):
  File "/home/user/wttr.in/lib/location.py", line 39, in is_ip
    socket.inet_pton(socket.AF_INET, ip_addr.encode("utf-8"))
TypeError: inet_pton() argument 2 must be str, not bytes

This python issue returns a 500 HTTP code.
Thanks for your help

Yes, it is a python 3 problem again; please try to remove .encode("utf-8") here

Now Python 3 is fully supported and should be used to run wttr.in.
Python 2 is out of support now

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andy-twosticks picture andy-twosticks  路  5Comments

chubin picture chubin  路  10Comments

Quenty-tolosan picture Quenty-tolosan  路  9Comments

stevensona picture stevensona  路  4Comments

bahamas10 picture bahamas10  路  10Comments