I am trying to access a resource for which I have to implement Oauth1 authorization. When I am using from postman with the option to add empty parameters to signature its working fine but when I am trying to implement the same thing with Python its throwing error.
This is my python code So please tell me what are the changes i have to make
import requests
import json
from requests_oauthlib import OAuth1Session
from requests_oauthlib import OAuth1
import urllib
import random
import time
from hashlib import sha1
import hmac
def sign_request(epocTime,nounce):
key = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX'
url = "GET&https://XXXXXXXXXXXXXXXXXXXXX/api/XXXXXXXXXXXXX&oauth_consumer_key=XXXXXXX&oauth_nonce=12345&oauth_signature_method=HMAC-SHA1&oauth_timestamp={}&oauth_version=1.0".format(epoch_time)
raw = urllib.quote(url)
hashed = hmac.new(key, raw, sha1)
print hashed
return hashed.digest().encode("base64")
def test():
nounce = "12345"
epoch_time = int(time.time())
url = "https://XXXXXXXXXXXXXX/api/XXXXXXXXXXXXXXXXXXXXXX"
strr = sign_request(epoch_time,nounce)
print strr
querystring = {"oauth_consumer_key":"1XXXXXXXXXXXXXXXXX","oauth_token":"",
"oauth_signature_method":"HMAC-SHA1","oauth_timestamp":epocTime,
"oauth_nonce":nounce,"oauth_version":"1.0",
"oauth_signature":strr}
response = requests.request("GET", url, params=querystring)
print response.text
test()