Created
January 28, 2011 18:09
-
-
Save milin/800669 to your computer and use it in GitHub Desktop.
django.test.client import Client gives django_settings_module not specified problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import django | |
import httplib2 | |
import time,urlparse,urllib | |
from django.conf import settings | |
import oauth2 as oauth | |
from django.test.client import Client | |
CONSUMER_KEY = '123123123' | |
CONSUMER_SECRET = 'abcabcabc' | |
REQUEST_TOKEN_URL = 'http://localhost:8000/oauth/request_token/' | |
AUTHORIZE_URL = 'http://localhost:8000/oauth/authorize/?oauth_token=' | |
ACCESS_TOKEN_URL = 'http://localhost:8000/oauth/access_token/' | |
#parameters = {'oauth_consumer_key': CONSUMER_KEY,'oauth_signature_method': 'PLAINTEXT','oauth_signature': '%s&' %CONSUMER_SECRET,'oauth_timestamp': str(int(time.time())),'oauth_nonce':'requestnonce','oauth_version': '1.0','oauth_callback': 'http://localhost:8000','scope':'customer',} | |
c = Client() | |
parameters = {'oauth_consumer_key': CONSUMER_KEY,'oauth_signature_method': 'PLAINTEXT','oauth_signature': '%s&' % CONSUMER_SECRET,'oauth_timestamp': str(int(time.time())),'oauth_nonce': 'requestnonce','oauth_version': '1.0','oauth_callback': 'http://localhost:8000','scope': 'offer',} | |
params = urllib.urlencode(parameters) | |
#resp, content = client.request('http://localhost:8000/oauth/request_token','GET',params) | |
#c= httplib2.Http() | |
#c = Client() | |
#content=urllib.urlopen('http://localhost:8000/oauth/request_token/',parameters ).read() | |
#resp, content = c.request('http://localhost:8000/oauth/request_token/',params) | |
#response,content = client.request(REQUEST_TOKEN_URL, parameters) | |
response = c.get('http://localhost:8000/oauth/request_token/',parameters) | |
print response | |
#print content | |
accessDict = dict(urlparse.parse_qsl(content)) | |
print accessDict | |
#request_token = accessDict['oauth_token'] | |
#request_token_secret = accessDict['oauth_token_secret'] | |
print 'The request token for you is ' + request_token | |
print 'Please go to this url and authorize' + AUTHORIZE_URL + request_token | |
accepted = 'n' | |
while accepted.lower() == 'n': | |
accepted = raw_input('Have you authorized me?()y/n') | |
oauth_verifier = raw_input('what is the verifier') | |
c = Client() | |
parameters = {'oauth_consumer_key': CONSUMER_KEY,'oauth_token': request_token,'oauth_signature_method': 'PLAINTEXT','oauth_signature': '%s&%s' % (CONSUMER_SECRET, request_token_secret),'oauth_timestamp': str(int(time.time())),'oauth_nonce': 'accessnonce','oauth_version': '1.0','oauth_verifier': oauth_verifier,'scope': 'offer',} | |
response,content = client.request(ACCESS_TOKEN_URL,parameters,'GET') | |
accessDict = dict(urlparse.parse_qsl(content)) | |
access_token = accessDict['oauth_token'] | |
access_token_secret = accessDict['oauth_token_secret'] | |
print 'The request token for you is ' + access_token |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment