truly-systems / glpi-sdk-python

GLPI SDK writen in Python.
Apache License 2.0
22 stars 21 forks source link

TypeError: Can't convert 'bytes' object to str implicitly #11

Open jukebox opened 7 years ago

jukebox commented 7 years ago
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/glpi/glpi.py", line 221, in set_session_token
    err = _glpi_html_parser(r.content)
  File "/usr/local/lib/python3.5/dist-packages/glpi/glpi.py", line 100, in _glpi_html_parser
    html_parser = GlpiHTMLParser(content)
  File "/usr/local/lib/python3.5/dist-packages/glpi/glpi.py", line 76, in __init__
    self.feed(content)
  File "/usr/lib/python3.5/html/parser.py", line 110, in feed
    self.rawdata = self.rawdata + data
TypeError: Can't convert 'bytes' object to str implicitly

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "testgplisdk.py", line 4, in <module>
    g.get_all('ticket')
  File "/usr/local/lib/python3.5/dist-packages/glpi/glpi.py", line 517, in get_all
    self.init_api()
  File "/usr/local/lib/python3.5/dist-packages/glpi/glpi.py", line 481, in init_api
    self.api_session = self.api_rest.get_session_token()
  File "/usr/local/lib/python3.5/dist-packages/glpi/glpi.py", line 236, in get_session_token
    self.set_session_token()
  File "/usr/local/lib/python3.5/dist-packages/glpi/glpi.py", line 224, in set_session_token
    err = _glpi_html_parser(r.content)
  File "/usr/local/lib/python3.5/dist-packages/glpi/glpi.py", line 100, in _glpi_html_parser
    html_parser = GlpiHTMLParser(content)
  File "/usr/local/lib/python3.5/dist-packages/glpi/glpi.py", line 76, in __init__
    self.feed(content)
  File "/usr/lib/python3.5/html/parser.py", line 110, in feed
    self.rawdata = self.rawdata + data
TypeError: Can't convert 'bytes' object to str implicitly

`

NikiN2 commented 6 years ago

such an error was when the nginx was configured incorrectly, after adjusting according to the example from the documentation it became ok

poikilotherm commented 6 years ago

I'm running into the exact same issue whenever I receive an error response from GLPI.

@NikiN2: Could you describe a bit more in detail, what caused your problem and made it go away?

Thanks!

NikiN2 commented 6 years ago

@poikilotherm I used the config from the documentation and the bugs were gone https://github.com/glpi-project/glpi/blob/master/apirest.md#servers-configuration

poikilotherm commented 6 years ago

Thanks for the link :-) Actually, I'm not using URL rewriting within my config, just plain apirest.php.

@mtulio are you sure this is no bug within the SDK while handling the HTML response?

@NikiN2 can you reproduce the error without the rewrite? I was getting the error while I had a wrong App-Token in use...