aipescience / uws-client

IVOA UWS service command line client
Apache License 2.0
11 stars 9 forks source link

Python3 support #40

Open stephenpardy opened 7 years ago

stephenpardy commented 7 years ago

Does not currently support Python3. First noticed when tried to import client:

ImportError Traceback (most recent call last)

in () 8 matplotlib.rcParams.update(matplotlib.rcParamsDefault) 9 ---> 10 import uws.UWS.client as client 11 12 get_ipython().magic('matplotlib inline') /usr/local/lib/python3.5/site-packages/uws/UWS/__init__.py in () 1 # -*- coding: utf-8 -*- ----> 2 import client 3 import connection 4 import models 5 ImportError: No module named 'client' The error arises because Python3 needs relative imports to be explicitly defined.
lupinix commented 7 years ago

Yep, just checked that too. Imports and prints can be fixed quite easily using the 2to3 tool. But there are also differences in byte/string handling (see example below). These can be fixed by usage of six

`--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /home/lupinix/uws-client/venv/lib64/python3.5/base64.py in _input_type_check(s) 517 try: --> 518 m = memoryview(s) 519 except TypeError as err:

TypeError: memoryview: a bytes-like object is required, not 'str'

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

TypeError Traceback (most recent call last)

in () ----> 1 cli = client.Client(url, username, password) /home/lupinix/uws-client/uws/UWS/client.py in __init__(self, url, user, password, connection) 15 self.connection = connection 16 else: ---> 17 self.connection = UWSConnection.Connection(url, user, password) 18 19 def get_job_list(self, filters=None): /home/lupinix/uws-client/uws/UWS/connection.py in __init__(self, url, user, password) 13 14 if user is not None and password is not None: ---> 15 self.auth_string = base64.encodestring('%s:%s' % (user, password)) 16 self.auth_string = self.auth_string.replace('\n', '') 17 self.headers = {"Authorization": "Basic %s" % self.auth_string} /home/lupinix/uws-client/venv/lib64/python3.5/base64.py in encodestring(s) 545 warnings.warn("encodestring() is a deprecated alias, use encodebytes()", 546 DeprecationWarning, 2) --> 547 return encodebytes(s) 548 549 /home/lupinix/uws-client/venv/lib64/python3.5/base64.py in encodebytes(s) 533 """Encode a bytestring into a bytes object containing multiple lines 534 of base-64 data.""" --> 535 _input_type_check(s) 536 pieces = [] 537 for i in range(0, len(s), MAXBINSIZE): /home/lupinix/uws-client/venv/lib64/python3.5/base64.py in _input_type_check(s) 519 except TypeError as err: 520 msg = "expected bytes-like object, not %s" % s.__class__.__name__ --> 521 raise TypeError(msg) from err 522 if m.format not in ('c', 'b', 'B'): 523 msg = ("expected single byte elements, not %r from %s" % TypeError: expected bytes-like object, not str`
stephenpardy commented 7 years ago

I managed to kludge together a fix for the byte-string issue, and switch the imports and print statements, but then I got a 403 error when trying to submit a request:

UWSError: No permission to access this resource

I checked the credentials on the online version and confirmed that I could actually login. Perhaps related to the byte-string issue, or something else?

viogp commented 3 years ago

I see a pull request that with the description "Python3 support", could this be integrated? Right now, with the python3 installation (python3 -m pip install uws-client) something is not working properly:

''' File ".../python3.8/site-packages/uws/UWS/init.py", line 2, in import client ModuleNotFoundError: No module named 'client'

'''

The module client is there, though.