Dear web2py users,
The Book twitter post recipe has errors. I know about 2 of them. I
could use some help with the last one.
Here is the code from the book in chapter 12.
def post_tweet(username,password,message):
import urllib, urlib2, base64
import gluon.contrib.simplejson as sj
args= urllib.urlencode([('status',message)])
headers={}
headers['Authorization'] = 'Basic '+base64.b64encode(username
+':'+password)
request = urllib2.Request('http://twitter.com/statuses/
update.json', args, headers)
return sj.loads(urllib2.urlopen(req).read())
import urllib, urlib2, base64
should be
import urllib, urllib2, base64
request = urllib2.Request('http://twitter.com/statuses/
update.json', args, headers)
should be
req = urllib2.Request('http://twitter.com/statuses/update.json',
args, headers)
Here is the help i need. The
return sj.loads(urllib2.urlopen(req).read())
statement causes
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 401: Unauthorized
I am sure I am using a valid user name and password. Does anyone have
any ideas?
I suspect the first argument to the urllib2.Request method ==
'http://twitter.com/statuses/update.json'
I think '/statuses/' could possibly be a misspelling. Does anyone
know?
Thanks for the help in advance.
Love and peace,
Joe