Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WinError 10013 when trying to create calendar object #49

Closed
neurognome opened this issue Oct 22, 2020 · 3 comments
Closed

WinError 10013 when trying to create calendar object #49

neurognome opened this issue Oct 22, 2020 · 3 comments

Comments

@neurognome
Copy link

neurognome commented Oct 22, 2020

I think this is potentially due to either attempting to run this on a computer that's managed by my organization or something, but when I try to just run the first line to instantiate a "calendar" object, I get this error:

Traceback (most recent call last):
  File "test2.py", line 8, in <module>
    calendar = GoogleCalendar('myemail@gmail.com')
  File "E:\_TemporaryBetaCode\CalendarBooker\google-calendar-simple-api\gcsa\google_calendar.py", line 56, in __init__
    credentials = self._get_credentials()
  File "E:\_TemporaryBetaCode\CalendarBooker\google-calendar-simple-api\gcsa\google_calendar.py", line 73, in _get_credentials
    credentials = flow.run_local_server()
  File "C:\Users\sit\Anaconda3\lib\site-packages\google_auth_oauthlib\flow.py", line 442, in run_local_server
    local_server = wsgiref.simple_server.make_server(
  File "C:\Users\sit\Anaconda3\lib\wsgiref\simple_server.py", line 154, in make_server
    server = server_class((host, port), handler_class)
  File "C:\Users\sit\Anaconda3\lib\socketserver.py", line 452, in __init__
    self.server_bind()
  File "C:\Users\sit\Anaconda3\lib\wsgiref\simple_server.py", line 50, in server_bind
    HTTPServer.server_bind(self)
  File "C:\Users\sit\Anaconda3\lib\http\server.py", line 138, in server_bind
    socketserver.TCPServer.server_bind(self)
  File "C:\Users\sit\Anaconda3\lib\socketserver.py", line 466, in server_bind
    self.socket.bind(self.server_address)
OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions
@kuzmoyev
Copy link
Owner

kuzmoyev commented Oct 22, 2020

I think the problem is that google_auth_oauthlib runs its authentication flow server on the port 8080 by default which might be occupied by something else in your system.

Try netstat -a -b -n and check if this port is in use. If you can, quit the application that uses it. If not it would require overriding the _get_credentials of GoogleCalendar like so:

class GoogleCalendarOnAnotherPort(GoogleCalendar):    
    def _get_credentials(self):
        _credentials_path = os.path.join(self._credentials_dir, self._credentials_file)

        credentials = None

        if os.path.exists(self._token_path):
            with open(self._token_path, 'rb') as token:
                credentials = pickle.load(token)

        if not credentials or not credentials.valid:
            if credentials and credentials.expired and credentials.refresh_token:
                credentials.refresh(Request())
            else:
                flow = InstalledAppFlow.from_client_secrets_file(_credentials_path, self._scopes)
                credentials = flow.run_local_server(port=8090) # note the port parameter. Change to any free port

            with open(self._token_path, 'wb') as token:
                pickle.dump(credentials, token)

        return credentials

It is a workaround and should be fixed in the future version of the gcsa.

Thank you for the issue submission.

@neurognome
Copy link
Author

Perfect! That was exactly the issue, I set it to use a different port and everything is working great.

Thanks so much.

@kuzmoyev kuzmoyev reopened this Oct 22, 2020
@kuzmoyev
Copy link
Owner

I'll leave the issue open until it is fixed in the implementation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants