Constructing requests with URL Query String in Python

I’m not really sure what I’m doing. Should I be using a library for this? Or do it manually?

So I’m trying to do some work with the WiThings ( API in Python.

In order to perform some of the requests, OAuth authentication is required. I have gone through using the requests library and obtained an oauth token and secret token, alongside my consumer and consumer secret tokens.

Now I am at the point of having to make requests, and I am running into some problems. The format for the request I need to make is as follows (an example from their API):

As far as I can tell, this is pretty much a typical format with OAuth, except for the userid at the end.

So, is it possible for me to make a request like this using the requests library? Or some other library? How do I get the URL right, with the comment and userid and callbackurl fields? Or do I need to generate this URL manually? If that’s the case, whats the best way for going about doing this?

Any assistance is greatly appreciated, as I’ve been stuck on this for a while.


So, for some clarification, I understand about 98% of the code I am being referred to. I am only having a little problem at the end.

So here I am, with the following code:

from __future__ import unicode_literals
from urlparse import parse_qs
import requests
from requests_oauthlib import OAuth1Session

consumer_key = '**Valid consumer key**'

consumer_secret = '**Valid consumer secret**'

oauth_key = '**Valid oauth key obtained through requests library and OAuth workflow**'

oauth_secret ='**Valid oauth secret obtained through requests library and OAuth workflow**'

verifier = '**Valid consumer key obtained through requests library and OAuth workflow**'

base_url = ''

params = {
'action': 'subscribe',
'callbackurl': '**callback URL**',
'comment': '**comment**',
'oauth_consumer_key': '**consumer_key**',
'oauth_nonce': 'etc etc',
'oauth_signature' : '' # <-------------- Where do I get this
# etc etc... I have everything else
r = requests.get("", params=params)

This is all I need. I have everything I need but the signature. Is there a way I can get the signature from the oauth libraries? This is all that has been holding me up.

Leave a Comment