googleworkspace / python-samples

🐍 Python samples for Google Workspace APIs
Apache License 2.0
1.2k stars 892 forks source link

Quickstart.py - 'utf-8' codec can't decode byte 0xe6 #138

Closed fredrikj31 closed 4 years ago

fredrikj31 commented 4 years ago

Expected Behavior

I wanted to use the Google Calendar Api for python but ran into a bug. I wanted to start to list all the available calendars for the user.

I was searching for at solution on the problem, but none of them seems to fix it. Somebody said that the default windows console does not support Unicode but I dont know if that's the error.

I don't know if it's because im using a danish calendar. We have some wired characters 😂

Actual Behavior

When im running the program im getting this error:

Traceback (most recent call last):
  File "quickstart.py", line 67, in <module>
    main()
  File "quickstart.py", line 45, in main
    creds = flow.run_local_server(port=0)
  File "C:\Users\fredr\AppData\Local\Programs\Python\Python37-32\lib\site-packages\google_auth_oauthlib\flow.py", line 425, in run_local_server
    host, port, wsgi_app, handler_class=_WSGIRequestHandler)
  File "C:\Users\fredr\AppData\Local\Programs\Python\Python37-32\lib\wsgiref\simple_server.py", line 153, in make_server
    server = server_class((host, port), handler_class)
  File "C:\Users\fredr\AppData\Local\Programs\Python\Python37-32\lib\socketserver.py", line 452, in __init__
    self.server_bind()
  File "C:\Users\fredr\AppData\Local\Programs\Python\Python37-32\lib\wsgiref\simple_server.py", line 50, in server_bind
    HTTPServer.server_bind(self)
  File "C:\Users\fredr\AppData\Local\Programs\Python\Python37-32\lib\http\server.py", line 139, in server_bind
    self.server_name = socket.getfqdn(host)
  File "C:\Users\fredr\AppData\Local\Programs\Python\Python37-32\lib\socket.py", line 676, in getfqdn
    hostname, aliases, ipaddrs = gethostbyaddr(name)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe6 in position 9: invalid continuation byte

Steps to Reproduce the Problem

  1. Clone the repository from google apis official github repository
  2. Then get the credentials.json file
  3. Run the quickstart.py

Specifications

sqrrrl commented 4 years ago

It's not the calendar events -- this is happening way earlier than that while trying to start a local server to handle oauth callback.

Unfortunately I think this is a Python issue -- do you have non-ascii chars in your hostname? If so, likely related to https://bugs.python.org/issue26227 (or one of the other issues referenced in the comments.) If that is the cause, might be able to work around it by changing your hostname.

Not sure what version of Python it is fixed in, but also might want to try upgrading to latest Python if you're able.

fredrikj31 commented 4 years ago

I am sure that I do not have non-ASCII characters in my hostname. I kept it as default http://localhost. But I think that I found a solution, that I'm going to use the NodeJS Library, and then for the data make an API.

But thanks for trying to solve the problem!

sqrrrl commented 4 years ago

If you ever get around to trying new Python version, LMK :)