0

我正在尝试使用 Requests-OAuthlib 对 OAuth1 进行身份验证,但它失败了。我正在从以下网站获得帮助:

https://requests-oauthlib.readthedocs.io...#oauth-1-0

>> client_key = 'xxxx'
>> client_secret = 'xxxx'
>> callback_uri = 'https://127.0.0.1/callback'
>> request_token_url='https://rest.immobilienscout24.de/restapi/security/oauth/request_token',
>> access_token_url='https://rest.immobilienscout24.de/restapi/security/oauth/access_token',
>> authorize_url='https://rest.immobilienscout24.de/restapi/security/oauth/confirm_access',
>> oauth_session = OAuth1Session(client_key,client_secret=client_secret, callback_uri=callback_uri)
>> oauth_session.fetch_request_token(request_token_url)




Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/desktop/Documents/anaconda/anaconda3/envs/py27/lib/python2.7/site-packages/requests_oauthlib/oauth1_session.py", line 287, in fetch_request_token
    token = self._fetch_token(url, **request_kwargs)
  File "/Users/desktop/Documents/anaconda/anaconda3/envs/py27/lib/python2.7/site-packages/requests_oauthlib/oauth1_session.py", line 365, in _fetch_token
    r = self.post(url, **request_kwargs)
  File "/Users/desktop/Documents/anaconda/anaconda3/envs/py27/lib/python2.7/site-packages/requests/sessions.py", line 578, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/Users/desktop/Documents/anaconda/anaconda3/envs/py27/lib/python2.7/site-packages/requests/sessions.py", line 516, in request
    prep = self.prepare_request(req)
  File "/Users/desktop/Documents/anaconda/anaconda3/envs/py27/lib/python2.7/site-packages/requests/sessions.py", line 459, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "/Users/desktop/Documents/anaconda/anaconda3/envs/py27/lib/python2.7/site-packages/requests/models.py", line 318, in prepare
    self.prepare_auth(auth, url)
  File "/Users/desktop/Documents/anaconda/anaconda3/envs/py27/lib/python2.7/site-packages/requests/models.py", line 549, in prepare_auth
    r = auth(self)
  File "/Users/desktop/Documents/anaconda/anaconda3/envs/py27/lib/python2.7/site-packages/requests_oauthlib/oauth1_auth.py", line 109, in __call__
    unicode(r.url), unicode(r.method), None, r.headers
  File "/Users/desktop/Documents/anaconda/anaconda3/envs/py27/lib/python2.7/site-packages/oauthlib/oauth1/rfc5849/__init__.py", line 313, in sign
    ('oauth_signature', self.get_oauth_signature(request)))
  File "/Users/desktop/Documents/anaconda/anaconda3/envs/py27/lib/python2.7/site-packages/oauthlib/oauth1/rfc5849/__init__.py", line 136, in get_oauth_signature
    normalized_uri = signature.base_string_uri(uri, headers.get('Host', None))
  File "/Users/desktop/Documents/anaconda/anaconda3/envs/py27/lib/python2.7/site-packages/oauthlib/oauth1/rfc5849/signature.py", line 144, in base_string_uri
    raise ValueError('uri must include a scheme and netloc')
ValueError: uri must include a scheme and netloc

Anyhelp如何解决这个问题

4

1 回答 1

0

据我了解,此错误是由以下原因引起的:

normalized_uri = signature.base_string_uri(uri, headers.get('Host', None))

在此代码中,uriis None,因此它将Host在标题中使用:

headers.get('Host', None)

但是,a Hostin 标头将不包含架构,aHost看起来像:

www.google.com

没有。https://_ Host您可能需要向库报告错误。


还有另一个库(我是作者),它与 requests-oauthlib 共享一个熟悉的 API,您可以查看:https ://docs.authlib.org/en/latest/client/oauth1.html

from authlib.integrations.requests_client import OAuth1Session
于 2020-07-21T14:08:52.643 回答