ns1 / nsone-python

NS1 Python SDK
https://nsone.net
MIT License
19 stars 20 forks source link

Python3.6 - Twisted HTTP client expects bytes #34

Closed destroyhimmyrobots closed 4 years ago

destroyhimmyrobots commented 7 years ago

Hello,

While exploring the NS1 client, I was unable to list the zones for a certain API key. This appears to be an issue with either Twisted, or the way that NS1 calls into Twisted.

The code to reproduce, below, was tested with Twisted 17.1.0 and Twisted 17.5.0.

$ python3.6 -m venv virtualenv
$ pip install pyopenssl service_identity 'twisted[tls]==17.1.0' nsone
$ . virtualenv/bin/activate && python

>>> from nsone import Config, NSONE
>>> c = Config('./conf/nsone.json')
>>> a = NSONE(config=c)
>>> a.zones().list()

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/m/Documents/src/gitlab.com/tenome/mono-repo/interview/ctci-go/actual/ns1/virtualenv/lib/python3.6/site-packages/nsone/rest/zones.py", line 56, in list
    errback=errback)
  File "/Users/m/Documents/src/gitlab.com/tenome/mono-repo/interview/ctci-go/actual/ns1/virtualenv/lib/python3.6/site-packages/nsone/rest/resource.py", line 73, in _make_request
    return self._transport.send(type, self._make_url(path), **kwargs)
  File "/Users/m/Documents/src/gitlab.com/tenome/mono-repo/interview/ctci-go/actual/ns1/virtualenv/lib/python3.6/site-packages/nsone/rest/transport/twisted.py", line 169, in send
    d = self.agent.request(method, str(url), theaders, bProducer)
  File "/Users/m/Documents/src/gitlab.com/tenome/mono-repo/interview/ctci-go/actual/ns1/virtualenv/lib/python3.6/site-packages/twisted/web/client.py", line 1623, in request
    parsedURI = URI.fromBytes(uri)
  File "/Users/m/Documents/src/gitlab.com/tenome/mono-repo/interview/ctci-go/actual/ns1/virtualenv/lib/python3.6/site-packages/twisted/web/client.py", line 630, in fromBytes
    scheme, netloc, path, params, query, fragment = http.urlparse(uri)
  File "/Users/m/Documents/src/gitlab.com/tenome/mono-repo/interview/ctci-go/actual/ns1/virtualenv/lib/python3.6/site-packages/twisted/web/http.py", line 180, in urlparse
    raise TypeError("url must be bytes, not unicode")
TypeError: url must be bytes, not unicode

Here is the nsone.json configuration file:

{
  "api_version": "v1",
  "default_key": "key-one",
  "verbosity": 5,
  "transport": "twisted",
  "keys": {
    "key-one": {
      "key": "<<REDACTED>>",
      "desc": "NS1 API Key",
      "writeLock": true
    }
  },
  "cli": {
    "output_format": "text"
  }
}
Zach-Johnson commented 4 years ago

Hi @destroyhimmyrobots I'm going to close out this issue since this project is deprecated. If this is still an issue for you feel free to open another issue on https://github.com/ns1/ns1-python