Forums

oauthlib OSError: [Errno 98] Address already in use

I am stuck with this error: OSError: [Errno 98] Address already in use

I tried every possible solution but still no luck. I am using oauthlib to authorize the user but when the user is redirected back to the website it get stuck and loads for ever.

However loading the website without authorization works fine.

my main app : if name =="main": path = "/home/kxchan86/project" if path not in sys.path: sys.path.insert(0, path) print(sys.path) app.run()

error:

Traceback (most recent call last): File "/home/kxchan86/.virtualenvs/venv/lib/python3.8/site-packages/flask/app.py", line 2077, in wsgi_app response = self.full_dispatch_request() File "/home/kxchan86/.virtualenvs/venv/lib/python3.8/site-packages/flask/app.py", line 1525, in full_dispatch_request rv = self.handle_user_exception(e) File "/home/kxchan86/.virtualenvs/venv/lib/python3.8/site-packages/flask/app.py", line 1523, in full_dispatch_request rv = self.dispatch_request() File "/home/kxchan86/.virtualenvs/venv/lib/python3.8/site-packages/flask/app.py", line 1509, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args) File "/home/kxchan86/project/main.py", line 375, in home service = Create_Service(Client_Sercret_File,API_NAME,API_VERSION,SCOPES) File "/home/kxchan86/project/Google.py", line 34, in Create_Service cred = flow.run_local_server() File "/home/kxchan86/.virtualenvs/venv/lib/python3.8/site-packages/google_auth_oauthlib/flow.py", line 457, in run_local_server local_server = wsgiref.simple_server.make_server( File "/usr/lib/python3.8/wsgiref/simple_server.py", line 154, in make_server server = server_class((host, port), handler_class) File "/usr/lib/python3.8/socketserver.py", line 452, in init self.server_bind() File "/usr/lib/python3.8/wsgiref/simple_server.py", line 50, in server_bind HTTPServer.server_bind(self) File "/usr/lib/python3.8/http/server.py", line 138, in server_bind socketserver.TCPServer.server_bind(self) File "/usr/lib/python3.8/socketserver.py", line 466, in server_bind self.socket.bind(self.server_address) OSError: [Errno 98] Address already in use


I am also facing the same problem. I have followed pythonanywhere guidelines for flask deployment and ensured I only call app.run() in main without specifiying host & port. The app currently works fine locally and I get authorized and redirected back to the site with no issues.

You are not able run your flask app with app.run() on Pythonanywhere. Take a look at https://help.pythonanywhere.com/pages/Flask

I followed all the guidelines in https://help.pythonanywhere.com/pages/Flask but I am still getting the same error

Where do you get that error? The newest errors are at the bottom of your error log.

Yes at the bottom of the page

2022-04-15 11:44:33,246: Exception on /homepage [GET]
Traceback (most recent call last):
  File "/home/kxchan86/.virtualenvs/venv/lib/python3.8/site-packages/flask/app.py", line 2077, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/kxchan86/.virtualenvs/venv/lib/python3.8/site-packages/flask/app.py", line 1525, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/kxchan86/.virtualenvs/venv/lib/python3.8/site-packages/flask/app.py", line 1523, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/kxchan86/.virtualenvs/venv/lib/python3.8/site-packages/flask/app.py", line 1509, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/home/kxchan86/project/main.py", line 375, in home
    service = Create_Service(Client_Sercret_File,API_NAME,API_VERSION,SCOPES)
  File "/home/kxchan86/project/Google.py", line 34, in Create_Service
    cred = flow.run_local_server()
  File "/home/kxchan86/.virtualenvs/venv/lib/python3.8/site-packages/google_auth_oauthlib/flow.py", line 457, in run_local_server
    local_server = wsgiref.simple_server.make_server(
  File "/usr/lib/python3.8/wsgiref/simple_server.py", line 154, in make_server
    server = server_class((host, port), handler_class)
  File "/usr/lib/python3.8/socketserver.py", line 452, in __init__
    self.server_bind()
  File "/usr/lib/python3.8/wsgiref/simple_server.py", line 50, in server_bind
    HTTPServer.server_bind(self)
  File "/usr/lib/python3.8/http/server.py", line 138, in server_bind
    socketserver.TCPServer.server_bind(self)
  File "/usr/lib/python3.8/socketserver.py", line 466, in server_bind
    self.socket.bind(self.server_address)
OSError: [Errno 98] Address already in use

What's flow.run_local_server() in /home/kxchan86/project/Google.py doing? It looks like your web app is trying to start a local server, which is causing the error.

i am following the code from googleworkspace to connect to google calendar in python. The code to connect to google calendar via python can be found below: https://developers.google.com/calendar/api/quickstart/python https://github.com/googleworkspace/python-samples/blob/master/calendar/quickstart/quickstart.py It works flawlessly locally and also at hawkhost for example and I am sure there is a way to get it working on pythonanywhere

Just for clarity, are you trying to set things up so that your website can send people visiting it to a Google auth page from which they can allow access to their calendar so that your site can then add stuff to that calendar? Or are you trying to write a website that allows people to add items to your own calendar?

Basically the website allows certain users (already have access) to access a shared calendar.

Are they meant to be adding the items to the calendar via their own Google logins? Or via the same credentials for everyone?