iancmcc / ouimeaux

Python API to Belkin WeMo devices

Home Page:http://pypi.python.org/pypi/ouimeaux

Repository from Github https://github.comiancmcc/ouimeauxRepository from Github https://github.comiancmcc/ouimeaux

TypeError: Type str doesn't support the buffer API (python 3.4)

DIYtechie opened this issue · comments

How can I avoid getting this error?

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/gevent/pywsgi.py", line 884, in handle_one_response
    self.run_application()
  File "/usr/local/lib/python3.4/dist-packages/gevent/pywsgi.py", line 871, in run_application
    self.process_result()
  File "/usr/local/lib/python3.4/dist-packages/gevent/pywsgi.py", line 860, in process_result
    for data in self.result:
  File "/usr/local/lib/python3.4/dist-packages/ouimeaux/subscribe.py", line 70, in _handle
    data = data.split("\n\n")[0]
TypeError: Type str doesn't support the buffer API
{'CONTENT_LENGTH': '189',
 'CONTENT_TYPE': 'text/xml; charset="utf-8"',
 'GATEWAY_INTERFACE': 'CGI/1.1',
 'HTTP_HOST': '192.168.3.6:8864',
 'HTTP_NT': 'upnp:event',
 'HTTP_NTS': 'upnp:propchange',
 'HTTP_SEQ': '0',
 'HTTP_SID': 'uuid:90c85032-1dd2-11b2-81b9-b20893bae8be',
 'PATH_INFO': '/',
 'QUERY_STRING': '',
 'REMOTE_ADDR': '192.168.3.4',
 'REMOTE_PORT': '4790',
 'REQUEST_METHOD': 'NOTIFY',
 'SCRIPT_NAME': '',
 'SERVER_NAME': 'raspberrypi',
 'SERVER_PORT': '8864',
 'SERVER_PROTOCOL': 'HTTP/1.1',
 'SERVER_SOFTWARE': 'gevent/1.1 Python/3.4',
 'wsgi.errors': <_io.TextIOWrapper name='<stderr>' mode='w' encoding='UTF-8'>,
 'wsgi.input': <gevent.pywsgi.Input object at 0x761691f0>,
 'wsgi.multiprocess': False,
 'wsgi.multithread': False,
 'wsgi.run_once': False,
 'wsgi.url_scheme': 'http',
 'wsgi.version': (1, 0)} failed with TypeError

Looks like wsgi.version is a tuple instead of a string. Some change in the
server, probably.
On Mon, Sep 5, 2016 at 2:46 PM PiRune notifications@github.com wrote:

How can I avoid getting this error?

Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/gevent/pywsgi.py", line 884, in handle_one_response
self.run_application()
File "/usr/local/lib/python3.4/dist-packages/gevent/pywsgi.py", line 871, in run_application
self.process_result()
File "/usr/local/lib/python3.4/dist-packages/gevent/pywsgi.py", line 860, in process_result
for data in self.result:
File "/usr/local/lib/python3.4/dist-packages/ouimeaux/subscribe.py", line 70, in _handle
data = data.split("\n\n")[0]
TypeError: Type str doesn't support the buffer API
{'CONTENT_LENGTH': '189',
'CONTENT_TYPE': 'text/xml; charset="utf-8"',
'GATEWAY_INTERFACE': 'CGI/1.1',
'HTTP_HOST': '192.168.3.6:8864',
'HTTP_NT': 'upnp:event',
'HTTP_NTS': 'upnp:propchange',
'HTTP_SEQ': '0',
'HTTP_SID': 'uuid:90c85032-1dd2-11b2-81b9-b20893bae8be',
'PATH_INFO': '/',
'QUERY_STRING': '',
'REMOTE_ADDR': '192.168.3.4',
'REMOTE_PORT': '4790',
'REQUEST_METHOD': 'NOTIFY',
'SCRIPT_NAME': '',
'SERVER_NAME': 'raspberrypi',
'SERVER_PORT': '8864',
'SERVER_PROTOCOL': 'HTTP/1.1',
'SERVER_SOFTWARE': 'gevent/1.1 Python/3.4',
'wsgi.errors': <_io.TextIOWrapper name='' mode='w' encoding='UTF-8'>,
'wsgi.input': <gevent.pywsgi.Input object at 0x761691f0>,
'wsgi.multiprocess': False,
'wsgi.multithread': False,
'wsgi.run_once': False,
'wsgi.url_scheme': 'http',
'wsgi.version': (1, 0)} failed with TypeError


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#138, or mute the thread
https://github.com/notifications/unsubscribe-auth/AADic2w53oTZznXFwngDnVJv45oYGzNHks5qnHGTgaJpZM4J1Shq
.

@iancmcc Thanks for you reply :) I must admit I'm not sure what that means. Should I change something in the server and how?

Naah, and also I was entirely wrong. Reading tracebacks on a phone leads to
mistakes :). The problem is that data is bytes being split with a string,
according to Google. If you change "\n\n" to b"\n\n", that may fix it.

On Tue, Sep 6, 2016 at 2:26 AM PiRune notifications@github.com wrote:

@iancmcc https://github.com/iancmcc Thanks for you reply :) I must
admit I'm not sure what that means. Should I change something in the server
and how?


You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
#138 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AADicwtKfkIz1McWcw8eWaIyYBdFvkj0ks5qnRWFgaJpZM4J1Shq
.

Unfortunately, that was the first thing I tried (after Googling), but that results in a new TypeError:

TypeError: an integer is required and

TypeError: ('Not a bytestring', '<html><body><h1>200 OK</h1></body></html>'

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/gevent/pywsgi.py", line 739, in _write_with_headers
    towrite.extend(data)
TypeError: an integer is required

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/gevent/pywsgi.py", line 884, in handle_one_response
    self.run_application()
  File "/usr/local/lib/python3.4/dist-packages/gevent/pywsgi.py", line 871, in run_application
    self.process_result()
  File "/usr/local/lib/python3.4/dist-packages/gevent/pywsgi.py", line 862, in process_result
    self.write(data)
  File "/usr/local/lib/python3.4/dist-packages/gevent/pywsgi.py", line 713, in write
    self._write_with_headers(data)
  File "/usr/local/lib/python3.4/dist-packages/gevent/pywsgi.py", line 741, in _write_with_headers
    raise TypeError("Not a bytestring", data)
TypeError: ('Not a bytestring', '<html><body><h1>200 OK</h1></body></html>')
{'CONTENT_LENGTH': '190',
 'CONTENT_TYPE': 'text/xml; charset="utf-8"',
 'GATEWAY_INTERFACE': 'CGI/1.1',
 'HTTP_HOST': '192.168.3.6:8885',
 'HTTP_NT': 'upnp:event',
 'HTTP_NTS': 'upnp:propchange',
 'HTTP_SEQ': '0',
 'HTTP_SID': 'uuid:8d1f14bc-1dd2-11b2-81ba-b20893bae8be',
 'PATH_INFO': '/',
 'QUERY_STRING': '',
 'REMOTE_ADDR': '192.168.3.4',
 'REMOTE_PORT': '3286',
 'REQUEST_METHOD': 'NOTIFY',
 'SCRIPT_NAME': '',
 'SERVER_NAME': 'raspberrypi',
 'SERVER_PORT': '8885',
 'SERVER_PROTOCOL': 'HTTP/1.1',
 'SERVER_SOFTWARE': 'gevent/1.1 Python/3.4',
 'wsgi.errors': <_io.TextIOWrapper name='<stderr>' mode='w' encoding='UTF-8'>,
 'wsgi.input': <gevent.pywsgi.Input object at 0x76223298>,
 'wsgi.multiprocess': False,
 'wsgi.multithread': False,
 'wsgi.run_once': False,
 'wsgi.url_scheme': 'http',
 'wsgi.version': (1, 0)} failed with TypeError

Still not anyone who can help with this error?

Great! :) Would love to have ouimeaux working with Python 3.4 so I can integrate with my other smart home Python scripts.

I had a similar error when running under Python 3.4:

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/gevent/pywsgi.py", line 936, in handle_one_response
    self.run_application()
  File "/usr/local/lib/python3.4/dist-packages/gevent/pywsgi.py", line 910, in run_application
    self.process_result()
  File "/usr/local/lib/python3.4/dist-packages/gevent/pywsgi.py", line 896, in process_result
    self.write(data)
  File "/usr/local/lib/python3.4/dist-packages/gevent/pywsgi.py", line 742, in write
    self._write_with_headers(data)
  File "/usr/local/lib/python3.4/dist-packages/gevent/pywsgi.py", line 764, in _write_with_headers
    self._write(data)
  File "/usr/local/lib/python3.4/dist-packages/gevent/pywsgi.py", line 727, in _write
    self._sendall(data)
  File "/usr/local/lib/python3.4/dist-packages/gevent/pywsgi.py", line 702, in _sendall
    self.socket.sendall(data)
  File "/usr/local/lib/python3.4/dist-packages/gevent/_socket3.py", line 409, in sendall
    data_memory = _get_memory(data)
  File "/usr/local/lib/python3.4/dist-packages/gevent/_socket3.py", line 36, in _get_memory
    mv = memoryview(data)
TypeError: memoryview: str object does not have the buffer interface
Fri Mar 10 16:36:24 2017 {'REMOTE_ADDR': '::ffff:192.168.10.64', 'HTTP_HOST': '192.168.10.61:8591', 'REMOTE_PORT': '4928', (hidden keys: 22)} failed with TypeError

fix in my case was changing line 21 in ouimeaux/subscribe.py

from

SUCCESS = '<html><body><h1>200 OK</h1></body></html>'

to

SUCCESS = b'<html><body><h1>200 OK</h1></body></html>'

@fahrmairm thank you :) I'll try this at my earliest opportunity.

No error so far :) It appears to be working, but will continue testing.