Open jaraco opened 10 years ago
In case it wasn't clear, I'm supplying a valid API key in line 9.
The issue lies with wordnik.swagger in the MethodRequest class. Only on Python 3.3, for any request where the method isn't specified, get_method returns the empty string. This was a defect I identified in Python 3.3 and which I patched for Python 3.4.
In jaraco.net, I've developed a more robust MethodRequest that works on multiple Python versions, including 3.3:
class MethodRequest(urllib.request.Request):
method = None
def __init__(self, *args, **kwargs):
"""
Construct a MethodRequest. Usage is the same as for
`urllib.request.Request` except it also takes an optional `method`
keyword argument. If supplied, `method` will be used instead of
the default.
"""
method = kwargs.pop('method', self.method)
urllib.request.Request.__init__(self, *args, **kwargs)
# write the method after __init__ as Python 3.3 overrides the value
self.method = method
def get_method(self):
return getattr(self, 'method') or urllib.request.Request.get_method(self)
Consider using that technique in Wordnik.
Even that implementation has problems in some cases on some Pythons. I've put together a backports library: backports.method_request which is tested on Python 2.6+. Consider using that library or copying that code into Wordnik3.
At this point, I'd just recommend dropping support for Python 3.3 and earlier.
I tested the library on Python 3.4, and it seems to be working. I then deployed it on a system running Python 3.3 and I get 401 Unauthorized errors. Consider this test script:
If I have the wordnik-py3 2.1.2 eggs for Python 3.3 and Python 3.4 in the current directory, I can then run the above script for each. On Python 3.4, it passes without error. On Python 3.3, I get this traceback:
I'm using the exact same script, so the difference appears to be in how WordNik assembles the HTTP request on Python 3.3, somehow triggering the 401.