最近,我一直在努力让OAuth使用Python3.3来使用Python。作为参考,以下是WiThings的文档:http://www.withings.com/api
现在..。正如我所说的,我一直在使用WiThings中的Python,使用的是请求库(http://docs.python-requests.org/en/latest/)。据推测,这已经内置了对OAuth 1.0的支持。
使用它,当我输入我的消费者密钥和消费者机密,然后执行令牌请求时,我会得到这个响应……
b'<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">\n<html><head>\n<title>413 Request Entity Too Large</title>\n</head><body>\n<h1>Request Entity Too Large</h1>\nThe requested resource<br />/index.php<br />\ndoes not allow request data with POST requests, or the amount of data provided in\nthe request exceeds the capacity limit.\n<hr>\n<address>Apache Server at oauth.withings.com Port 80</address>\n</body></html>\n'知道是什么原因造成的吗?我有一种特定于WiThings的感觉...但他们的支持是可怕的。
接下来,我做了更多的研究,发现了这个:https://github.com/maximebf/python-withings
虽然文档也很差,但我安装了它,并编写了以下代码:
from __future__ import unicode_literals
from urllib.parse import parse_qs
import requests
from requests_oauthlib import OAuth1
import withings
CONSUMER_KEY = "omitted"
CONSUMER_SECRET = "omitted"
auth = WithingsAuth(CONSUMER_KEY, CONSUMER_SECRET)
authorize_url = auth.get_authorize_url()
print("Go to %s allow the app and copy your oauth_verifier" %authorize_url)
oauth_verifier = raw_input('Please enter your oauth_verifier: ')
creds = auth.get_credentials(oauth_verifier)
client = WithingsApi(creds)
measures = client.get_measures(limit=1)
print("Your last measured weight: %skg" % measures[0].weight) 并得到以下错误...
File "withings.py", line 5, in <module>
import withjings
File C:\User_Directory\withings.py", line 11, in <module>
auth = WithingsAuth(CONSUMER_KEY, CONSUMER_SECRET)
NameError: name 'WithingsAuth' is not defined在这两个问题上有什么帮助吗?有没有人在python中成功地使用过Withing?
感谢你们的帮助
发布于 2014-05-15 16:05:42
它应该是
from withings import WithingsAuth, WithingsApi 对我来说,它工作得很好,我能够提取我最后测量的体重。
发布于 2016-05-29 22:41:28
您需要从withings导入WithingsAuth,或者指定要使用withings.WithingsAuth。改变你的代码,它会变成:
from __future__ import unicode_literals
try:
from urllib.parse import parse_qs
except:
import urlparse as parse_qs
try:
input_method = raw_input
except:
input_method = input
import requests
from requests_oauthlib import OAuth1
import withings
CONSUMER_KEY = "omitted"
CONSUMER_SECRET = "omitted"
auth = withings.WithingsAuth(CONSUMER_KEY, CONSUMER_SECRET)
authorize_url = auth.get_authorize_url()
print("Go to %s allow the app and copy your oauth_verifier" %authorize_url)
oauth_verifier = input_method('Please enter your oauth_verifier: ')
creds = auth.get_credentials(oauth_verifier)
client = withings.WithingsApi(creds)
measures = client.get_measures(limit=1)
print("Your last measured weight: %skg" % measures[0].weight) https://stackoverflow.com/questions/17619474
复制相似问题