Google API oauth httpd server conflicts with SABNzbd+ in Python

一曲冷凌霜 提交于 2019-12-11 01:29:56

问题


I'm writing a Python app that interacts with a Google API and requires user authentication via oauth2.

I'm currently setting up a local authentication server to receive an oauth2 authentication code back from Google's oauth server, basically doing the oauth dance like this.

It usually works pretty well, but I guess I'm not understanding exactly how it's interacting with my ports, because it will happily assign my local authentication server to run on port 8080 even if some other app (in the case of my testing, SABNzbd++) is using that port.

I thought assigning the port to a used port number would result in an error and a retry. What am I doing wrong (or, alternatively, what is SABNzbd++ doing that keeps the fact that it's listening on port 8080 hidden from my app?)

The relevant code is as follows.

import socket
import BaseHTTPServer
from oauth2client.tools import ClientRedirectServer, ClientRedirectHandler

port_number = 0
host_name = 'localhost'
for port_number in range(8080,10000):
    try:
        httpd = ClientRedirectServer((host_name, port_number),
                                   ClientRedirectHandler)
    except socket.error, e:
        print "socket error: " + str(e)
        pass
    else:
        print "The server is running on: port " + str(port_number)
        print "and host_name " + host_name
        break

To clarify, the following are my expected results

socket error: [port already in use] (or something like that)
The server is running on: port 8081
and host_name localhost

and then going to localhost:8080 resolves to SABnzbd+, and localhost:8081 resolves to my authentication server.

I'm getting, howver:

the server is running on: port 8080
and host_name localhost

but going to localhost:8080 resolves to SABNzbd+

Thanks in advance!

来源:https://stackoverflow.com/questions/8641841/google-api-oauth-httpd-server-conflicts-with-sabnzbd-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!