persandstrom / python-verisure

A python module for reading and changing status of verisure devices through verisure app api.
MIT License
138 stars 42 forks source link

TypeError: must be str, not bytes #52

Closed christian-ek closed 7 years ago

christian-ek commented 7 years ago

Hi, Tried to run vsure but got an error.

pi@raspberrypi:~ $ vsure e-mail password get all Traceback (most recent call last): File "/usr/local/bin/vsure", line 11, in sys.exit(main()) File "/usr/local/lib/python3.4/dist-packages/verisure/main.py", line 174, in main with MyPages(args.username, args.password) as verisure: File "/usr/local/lib/python3.4/dist-packages/verisure/mypages.py", line 37, in enter self.login() File "/usr/local/lib/python3.4/dist-packages/verisure/mypages.py", line 50, in login self._session.login() File "/usr/local/lib/python3.4/dist-packages/verisure/session.py", line 97, in login response = self._session.send(req, timeout=RESPONSE_TIMEOUT) File "/usr/local/lib/python3.4/dist-packages/requests/sessions.py", line 609, in send r = adapter.send(request, **kwargs) File "/usr/local/lib/python3.4/dist-packages/requests/adapters.py", line 423, in send timeout=timeout File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 594, in urlopen chunked=chunked) File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 350, in _make_request self._validate_conn(conn) File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 835, in _validate_conn conn.connect() File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connection.py", line 311, in connect cert_reqs=resolve_cert_reqs(self.certreqs), File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/util/ssl.py", line 267, in create_urllib3_context context.set_ciphers(ciphers or DEFAULT_CIPHERS) File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/contrib/pyopenssl.py", line 385, in set_ciphers self._ctx.set_cipher_list(ciphers) TypeError: must be str, not bytes

persandstrom commented 7 years ago

Try to update to the latest version and see if the error persists. The command is vsure email passwd overview in the latest version.

christian-ek commented 7 years ago

I believe I have the latest version or am I doing something wrong? See below.


root@raspberrypi:/home/pi # pip install vsure
Requirement already satisfied: vsure in /usr/local/lib/python3.4/dist-packages
Requirement already satisfied: requests>=2.9.1 in /usr/local/lib/python3.4/dist-packages (from vsure)
root@raspberrypi:/home/pi # vsure MAIL PW overview
Traceback (most recent call last):
  File "/usr/local/bin/vsure", line 11, in <module>
    load_entry_point('vsure==1.0.0', 'console_scripts', 'vsure')()
  File "/usr/local/lib/python3.4/dist-packages/verisure/__main__.py", line 198, in main
    session.login()
  File "/usr/local/lib/python3.4/dist-packages/verisure/session.py", line 102, in login
    'Accept': 'application/json, text/javascript, */*; q=0.01',
  File "/usr/local/lib/python3.4/dist-packages/requests/api.py", line 110, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/requests/api.py", line 56, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/requests/sessions.py", line 488, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.4/dist-packages/requests/sessions.py", line 609, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/requests/adapters.py", line 423, in send
    timeout=timeout
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 594, in urlopen
    chunked=chunked)
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 350, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 835, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connection.py", line 311, in connect
    cert_reqs=resolve_cert_reqs(self.cert_reqs),
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/util/ssl_.py", line 267, in create_urllib3_context
    context.set_ciphers(ciphers or DEFAULT_CIPHERS)
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/contrib/pyopenssl.py", line 385, in set_ciphers
    self._ctx.set_cipher_list(ciphers)
TypeError: must be str, not bytes
persandstrom commented 7 years ago

Ah, you are correct, the latest version is not released to pypi yet. Try installing using pip install git+https://github.com/persandstrom/python-verisure.git.

christian-ek commented 7 years ago

Hi, Sadly still not working for me.

root@raspberrypi:/home/pi # pip install git+https://github.com/persandstrom/python-verisure.git
Collecting git+https://github.com/persandstrom/python-verisure.git
  Cloning https://github.com/persandstrom/python-verisure.git to /tmp/pip-zvkjc_nx-build
  Requirement already satisfied (use --upgrade to upgrade): vsure==1.1.0 from git+https://github.com/persandstrom/python-verisure.git in /usr/local/lib/python3.4/dist-packages
Requirement already satisfied: requests>=2.9.1 in /usr/local/lib/python3.4/dist-packages (from vsure==1.1.0)

root@raspberrypi:/home/pi # vsure mail pass overview
Traceback (most recent call last):
  File "/usr/local/bin/vsure", line 11, in <module>
    load_entry_point('vsure==1.1.0', 'console_scripts', 'vsure')()
  File "/usr/local/lib/python3.4/dist-packages/verisure/__main__.py", line 204, in main
    session.login()
  File "/usr/local/lib/python3.4/dist-packages/verisure/session.py", line 103, in login
    'Accept': 'application/json, text/javascript, */*; q=0.01',
  File "/usr/local/lib/python3.4/dist-packages/requests/api.py", line 110, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/requests/api.py", line 56, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/requests/sessions.py", line 488, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.4/dist-packages/requests/sessions.py", line 609, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/requests/adapters.py", line 423, in send
    timeout=timeout
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 594, in urlopen
    chunked=chunked)
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 350, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 835, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connection.py", line 311, in connect
    cert_reqs=resolve_cert_reqs(self.cert_reqs),
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/util/ssl_.py", line 267, in create_urllib3_context
    context.set_ciphers(ciphers or DEFAULT_CIPHERS)
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/contrib/pyopenssl.py", line 385, in set_ciphers
    self._ctx.set_cipher_list(ciphers)
TypeError: must be str, not bytes
persandstrom commented 7 years ago

Have you found any solution or cause? I have tried to recreate the error, but not succeeded.

christian-ek commented 7 years ago

No sadly i still get the same error

christian-ek commented 7 years ago

I get the same when trying module.

>>> import verisure
>>> session = verisure.Session('***@live.se', 'PW')
>>> session.login()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/dist-packages/verisure/session.py", line 103, in login
    'Accept': 'application/json, text/javascript, */*; q=0.01',
  File "/usr/local/lib/python3.4/dist-packages/requests/api.py", line 110, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/requests/api.py", line 56, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/requests/sessions.py", line 488, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.4/dist-packages/requests/sessions.py", line 609, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/requests/adapters.py", line 423, in send
    timeout=timeout
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 594, in urlopen
    chunked=chunked)
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 350, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 835, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connection.py", line 311, in connect
    cert_reqs=resolve_cert_reqs(self.cert_reqs),
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/util/ssl_.py", line 267, in create_urllib3_context
    context.set_ciphers(ciphers or DEFAULT_CIPHERS)
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/contrib/pyopenssl.py", line 385, in set_ciphers
    self._ctx.set_cipher_list(ciphers)
TypeError: must be str, not bytes
>>>
tomhur commented 7 years ago

I'm also having these problems. I have made sure I have the latest update:

python3.5 -m pip install --upgrade git+https://github.com/persandstrom/python-verisure.git
Collecting git+https://github.com/persandstrom/python-verisure.git
  Cloning https://github.com/persandstrom/python-verisure.git to /tmp/pip-5sf7aiqa-build
Requirement already up-to-date: requests>=2.9.1 in /usr/lib/python3.5/site-packages (from vsure==1.3.3)
Installing collected packages: vsure
  Found existing installation: vsure 1.3.3
    Uninstalling vsure-1.3.3:
      Successfully uninstalled vsure-1.3.3
  Running setup.py install for vsure ... done
Successfully installed vsure-1.3.3

and I get this error when I use python 3.5:

python3.5
Python 3.5.3 (default, Mar 21 2017, 17:21:33) 
[GCC 6.3.1 20161221 (Red Hat 6.3.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import verisure
>>> mypages = verisure.Session("e-mail", "pass")
>>> mypages.login()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.5/site-packages/verisure/session.py", line 84, in login
    _validate_response(response)
  File "/usr/lib/python3.5/site-packages/verisure/session.py", line 15, in _validate_response
    raise ResponseError(response.status_code, response.text)
  File "/usr/lib/python3.5/site-packages/verisure/session.py", line 42, in __init__
    self.text = json.loads(text.encode('utf-8'))
  File "/usr/lib64/python3.5/json/__init__.py", line 312, in loads
    s.__class__.__name__))
TypeError: the JSON object must be str, not 'bytes'

But when I use python 2.7 it works (same version of python-verisure as above):

python
Python 2.7.13 (default, Jan 12 2017, 17:59:37) 
[GCC 6.3.1 20161221 (Red Hat 6.3.1-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import verisure
>>> mypages = verisure.Session("e-mail", "pass")
>>> mypages.login()
>>> mypages.get_arm_state()
{u'name': u'Hem Automation', u'area': u'REMOTE', u'cid': u'01029078', u'changedVia': u'REMOTE_APP', u'date': u'2017-04-02T06:07:41.000Z', u'statusType': u'DISARMED'}
persandstrom commented 7 years ago

Could you try the branch issue52 and see if that works or act different in any way?

tomhur commented 7 years ago

That works good for me :)

python3
Python 3.5.3 (default, Mar 21 2017, 17:21:33) 
[GCC 6.3.1 20161221 (Red Hat 6.3.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.insert(0,'/opt/python-verisure')
>>> import verisure
>>> mypages = verisure.Session("e-mail", "pass")
>>> mypages.login()
>>> mypages.get_arm_state()
{'changedVia': 'REMOTE_APP', 'date': '2017-04-02T06:07:41.000Z', 'area': 'REMOTE', 'cid': '01029078', 'name': 'Hem Automation', 'statusType': 'DISARMED'}

Great work!

persandstrom commented 7 years ago

@tomhur Nice!

I have released the fix in version 1.3.4

@christian-ek Could you verify and see if it works for you as well?

christian-ek commented 7 years ago

No, maybe I'm doing something wrong?

pi@raspberrypi:~ $ sudo pip install git+https://github.com/persandstrom/python-verisure.git
Collecting git+https://github.com/persandstrom/python-verisure.git
  Cloning https://github.com/persandstrom/python-verisure.git to /tmp/pip-1nkbbdg_-build
  Requirement already satisfied (use --upgrade to upgrade): vsure==1.3.4 from git+https://github.com/persandstrom/python-verisure.git in /usr/local/lib/python3.4/dist-packages
Requirement already satisfied: requests>=2.9.1 in /usr/local/lib/python3.4/dist-packages (from vsure==1.3.4)

pi@raspberrypi:~ $ python3
Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.insert(0,'/opt/python-verisure')
>>> import verisure
>>> mypages = verisure.Session("email", "pw")
>>> mypages.login()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/dist-packages/verisure/session.py", line 81, in login
    'Accept': 'application/json,'
  File "/usr/local/lib/python3.4/dist-packages/requests/api.py", line 110, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/requests/api.py", line 56, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/requests/sessions.py", line 488, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.4/dist-packages/requests/sessions.py", line 609, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/requests/adapters.py", line 423, in send
    timeout=timeout
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 594, in urlopen
    chunked=chunked)
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 350, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 835, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connection.py", line 311, in connect
    cert_reqs=resolve_cert_reqs(self.cert_reqs),
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/util/ssl_.py", line 267, in create_urllib3_context
    context.set_ciphers(ciphers or DEFAULT_CIPHERS)
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/contrib/pyopenssl.py", line 385, in set_ciphers
    self._ctx.set_cipher_list(ciphers)
TypeError: must be str, not bytes
>>>
persandstrom commented 7 years ago

@christian-ek I have a theory. You have a non ascii character in your credentials, right? I have updated the issue52 branch. Please test when you have time.

christian-ek commented 7 years ago

Working now, thank you :-)