Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I use urllib2 to post data to a sever?
    primarykey
    data
    text
    <p>I am making a python twitch.tv API Wrapper for python and so far I have :</p> <pre><code>import urllib2 import json import time waittime = 1 baseurl = 'https://api.twitch.tv/kraken/' secret = '(CLASSIFIED)' class twitchchannelinfo(): #Ignore me ;D I'm Here for reference's sake def __init__ (self,channel): self.channel = channel time.sleep(waittime) self.dict1 = json.loads(urllib2.urlopen(baseurl + 'channels/' + channel).read()) def getstatus(self): return self.dict1 ['status'] def getdisplay_name(self): return self.dict1 ['display_name'] def getmature(self): return self.dict1 ['mature'] def getchanurl(self): return self.dict1 ['url'] def getcreated_at(self): return self.dict1 ['created_at'] def getteams(self): return self.dict1 ['teams'] def getgame(self): return self.dict1 ['game'] def getupdated_at(self): return self.dict1 ['updated_at'] class twichtvwrapper(): def __init__(self,username,password): self.username = username self.password = password self.dict1 = json.loads(urllib2.urlopen(baseurl + 'oauth2/token',\ "client_id=&lt;3kfp6al05voejvv7ofmpc94g4jga0tb&gt;&amp;\ client_secret=&lt;" + secret + "&gt;&amp;\ username=&lt;" + self.username + "&gt;&amp;\ password=&lt;" + self.password + "&gt;&amp;\ scope=user_read&amp;\ grant_type=password")) print self.dict1 me = twichtvwrapper('martincharles07','(CLASSIFIED)') </code></pre> <p>(The secret is an API identifier and the password has been retracted for obvious reasons ;D).</p> <p>The server should return a JSON response like this:</p> <pre><code>{ "scope":["user_read"], "access_token":"df4yofxyn2s7240ojfrh9chz8" } </code></pre> <p><a href="https://github.com/justintv/Twitch-API/blob/master/password-credentials.md" rel="nofollow">Here is the API reference.</a></p> <p>The program crashes with the exception <code>urllib2.HTTPError: HTTP Error 400: Bad Request</code>. I don't know what I am doing wrong, is it the line splits or incorrect usage of urllib2? How can I fix it?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload