You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Traceback (most recent call last):
File "/tmp/example.py", line 3, in <module>
@twisted.internet.task.react
File "/home/mrw/.virtualenvs/tmp-963c1ecd0f4cfd34/lib/python2.7/site-packages/twisted/internet/task.py", line 908, in react
finished = main(_reactor, *argv)
File "/tmp/example.py", line 5, in run
return treq.get(hyperlink.URL.from_text(u"https://twistedmatrix.com/"))
File "/home/mrw/.virtualenvs/tmp-963c1ecd0f4cfd34/lib/python2.7/site-packages/treq/api.py", line 24, in get
return _client(**kwargs).get(url, headers=headers, **kwargs)
File "/home/mrw/.virtualenvs/tmp-963c1ecd0f4cfd34/lib/python2.7/site-packages/treq/client.py", line 109, in get
return self.request('GET', url, **kwargs)
File "/home/mrw/.virtualenvs/tmp-963c1ecd0f4cfd34/lib/python2.7/site-packages/treq/client.py", line 218, in request
bodyProducer=bodyProducer)
File "/home/mrw/.virtualenvs/tmp-963c1ecd0f4cfd34/lib/python2.7/site-packages/twisted/web/client.py", line 1973, in request
deferred = self._agent.request(method, uri, headers, bodyProducer)
File "/home/mrw/.virtualenvs/tmp-963c1ecd0f4cfd34/lib/python2.7/site-packages/twisted/web/client.py", line 2041, in request
deferred = self._agent.request(method, uri, headers, bodyProducer)
File "/home/mrw/.virtualenvs/tmp-963c1ecd0f4cfd34/lib/python2.7/site-packages/twisted/web/client.py", line 1838, in request
lastRequest = _FakeUrllib2Request(uri)
File "/home/mrw/.virtualenvs/tmp-963c1ecd0f4cfd34/lib/python2.7/site-packages/twisted/web/client.py", line 1720, in __init__
self.uri = nativeString(uri)
File "/home/mrw/.virtualenvs/tmp-963c1ecd0f4cfd34/lib/python2.7/site-packages/twisted/python/compat.py", line 412, in nativeString
raise TypeError("%r is neither bytes nor unicode" % s)
TypeError: URL.from_text(u'https://twistedmatrix.com/') is neither bytes nor unicode
python-hyper/hyperlink#55 means we can call bytes on URLs to get something we can pass Agent.request.
I definitely want to accept hyperlink.URL directly. When I use treq I often use hyperlink.URL to build the URLs I pass to treq. Since treq uses the class internally to manage IDN (and, once #265 is merged, params), I see no real downside to accepting hyperlink.URL — it's strictly fewer conversions. Plus, accepting the class allows us to highlight hyperlink as the useful and correct library it is. I think that users will often be better-served with hyperlink than any of the functions in urllib.parse.
You can't pass
treq
aURL
because of howtwisted.web.client.Agent
works:python-hyper/hyperlink#55 means we can call
bytes
onURL
s to get something we can passAgent.request
.On the one hand, calling
bytes
on any old object seems bad, but on the other, we already useURL
to convertunicode
URLs tobytes
.If there's any API change, I favor adding an
else
that doesurl = bytes(url)
, but we'd also need to fix_combine_query_params
.However, I think I prefer that
treq
only acceptbytes
andunicode
, and that we tell people to dobytes(theirURL)
themselves.The text was updated successfully, but these errors were encountered: