【问题标题】:Python Oauth Request to Twitter Yields Response 403 - SSL is Required对 Twitter 的 Python Oauth 请求产生响应 403 - 需要 SSL
【发布时间】:2014-04-03 22:18:31
【问题描述】:

使用 Python 的 oauth2 库,我一直在尝试向 Twitter 实现一个三足 oauth 请求(如此处所述 - http://www.linuxuser.co.uk/news/handling-twitters-three-legged-oauth-process),只是为了获得 403 响应 - “需要 SSL”错误。

我一直在使用本指南 (https://bitbucket.org/david/django-oauth-plus/wiki/consumer_example) 来帮助设置我的 1.5 Django 应用程序以提出我的请求,但无济于事。

我目前使用的 Python 版本是 2.7。

(我尝试过为 requests.get 调用添加验证参数并在我的客户端上使用 add_certificate)

我要确定的具体领域是如何将 SSL 添加到我的请求中,这里是目前的代码快照 --

import oauth2 as oauth
import requests
import urlparse

from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from django.conf import settings

from twitterapp.models import User

consumer = oauth.Consumer(settings.TWITTER_CONSUMER_KEY, settings.TWITTER_CONSUMER_SEC)
client = oauth.Client(consumer)
client.add_certificate

request_token_url = 'http://api.twitter.com/oauth/request_token'
access_token_url = 'http://api.twitter.com/oauth/access_token'
authorize_url='https://api.twitter.com/oauth/authorize'

def signin(request):
    oauth_request = oauth.Request.from_consumer_and_token(consumer, http_url=request_token_url, parameters={'oauth_callback':callback_url})
    oauth_request.sign_request(oauth.SignatureMethod_HMAC_SHA1(), consumer, None)
    response = requests.get(request_token_url, headers=oauth_request.to_header(), verify=True)
    request_token = dict(urlparse.parse_qsl(response.content))

    url = 'https://api.twitter.com/oauth/authorize?oauth_token=%s' % request_token['oauth_token']

    return HttpResponseRedirect(url)

【问题讨论】:

    标签: python django ssl twitter oauth


    【解决方案1】:

    这里:

    request_token_url = 'http://api.twitter.com/oauth/request_token'
    access_token_url = 'http://api.twitter.com/oauth/access_token'
    

    这些请求需要通过https://

    所以

    request_token_url = 'https://api.twitter.com/oauth/request_token'
    access_token_url = 'https://api.twitter.com/oauth/access_token'
    

    应该做的伎俩。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-10
      • 1970-01-01
      • 2011-04-10
      • 2022-01-18
      • 1970-01-01
      • 1970-01-01
      • 2019-02-21
      • 2022-01-20
      相关资源
      最近更新 更多