1

I followed Google's Quickstart for Python, step-by-step. I followed each step exactly, often copying and pasting. I definitely have the Google Calendar API enabled. I've installed the Google Client Library with Pip. I've set up the sample code and the credentials.json in its own folder. So, why am I getting this error when I run it:

"OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions"

To figure this out, I've learned what a socket is. (It's literally the combination of an IP address and a single port). I've learned how to use netstat, though I don't know yet how this applies to what I'm doing. I've looked into using ShellExecuteEx based on an answer in this question, but I don't know how to use that with Python.

I've tried adding the script from the accepted answer to this question (which actually uses the ShellExecuteEx method though I don't notice this) into an admin.py file and import this admin.py script into quickstart.py. After updating the admin.py script to Python 3 syntax and running quickstart.py, Windows 8.1 asks me if I will allow access. I say yes, and it still gives me the OSError (WinError 10013) on accessing the socket in a forbidden way. The UAC is not the issue.

I suspect it's a port conflict, where something's already using the port that the script that Google's trying to use. But I'm worried that the port is decided by a black box function that I won't be able to change. The error itself doesn't say which port it's using, so I'll need to do more research.

1 Answers1

0

It is a port issue.

  • Go to line 34 on the quickstart.py file (or where it says creds = run_local_server()).
  • Go to the flow.py file in the google_auth_oauthlib package with this function (in VS Code, click run_local_server() and press F12 or right click and select "Go to Definition").

You'll see line 369 (at the time of this writing) say self, host='localhost', port=8080,.

When I look at netstat, it actually says this port is in use, probably with an Apache server I never turned off.

Netstat TCP Port 8080, LISTENING

  • Change the value in the flow.py file in the google_auth_oauthlib package to 8090, so 369 looks like self, host='localhost', port=8090,.

I ran the quickstart.py script again, and the window to authenticate my Google account popped up.

I selected my account, and it worked. No messing with the admin stuff.

I'm glad I was able to find it like this because I thought the port was selected in some black box manner, like it was decided from a server at Google.