我连接到Twitter的流API和正在建立的OAuth握手。 我需要请求令牌并发送callback_url
与后请求一起作为PARAMS字典。
我已经硬编码在url发展(http://localhost:8000/oauth)
但是当我部署这种情况将会改变。 我想设置的东西,会发现主机和端口,并设置一个参考吧。 理想的情况下,看起来像"http://%s/oauth" % (domain_name)
我同时使用的操作系统和插座模块试过了,代码如下:
class OAuth:
def request_oauthtoken(self):
name = socket.gethostname()
ip = socket.gethostbyname(name)
domain = socket.gethostbyaddr(ip) # Sequence attempts to find the current domain name. This will add expandability to the calling the API, as opposed to hard coding it in. It's not returning what I'm expecting
payload = { 'oauth_callback': 'http://localhost:8000/oauth' }
print(domain)
return payload
domain
返回('justins-mbp-2.local.tld', ['145.15.168.192.in-addr.arpa'], ['192.168.15.145'])
name
返回上面的元组的第一个元素和ip
从集合返回解开元组的最后一个项目。
我正在寻找的返回值localhost
或localhost:8000
。 我可以与任何一个工作。