Google API oauth httpd 服务器与 SABNzbd 冲突+在Python中
我正在编写一个与 Google API 交互的 Python 应用程序,并需要通过 oauth2 进行用户身份验证。
我目前正在设置一个本地身份验证服务器,以接收从 Google 的 oauth 服务器返回的 oauth2 身份验证代码,基本上就像 这个。
它通常工作得很好,但我想我并不清楚它是如何与我的端口交互的,因为它会很高兴地分配我的本地身份验证服务器在端口 8080 上运行,即使其他应用程序(在我的测试中,SABNzbd++ )正在使用该端口。
我认为将端口分配给已使用的端口号会导致错误并重试。我做错了什么(或者,SABNzbd++ 做了什么,使其在我的应用程序中隐藏了它正在侦听端口 8080 的事实?)
相关代码如下。
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
为了澄清,以下是我的预期结果
socket error: [port already in use] (or something like that)
The server is running on: port 8081
and host_name localhost
,然后转到 localhost:8080 解析为 SABnzbd+,而 localhost:8081 解析为我的身份验证服务器。
不过,我明白了:
the server is running on: port 8080
and host_name localhost
但是转到 localhost:8080 会解析为 SABNzbd+
提前致谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论