Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: picobit on October 08, 2012, 02:49:12 PM



Title: [Solved] Help with Bitstamp API
Post by: picobit on October 08, 2012, 02:49:12 PM
Hi!

I am trying to use the Bitstamp API, but it apparently refuses to recognize my userid and password.   I have enabled API access in the settings, and I tried disabling 2-factor authentication to no avail.

I am using this Python script, can anyone help me find the problem?
Code:
import urllib2
from urllib import urlencode
import json

user="12345"
passwd="top-secret"

req = {}
req['user'] = user
req['password'] = passwd
post_data = urlencode(req)
print post_data
res = urllib2.urlopen("https://www.bitstamp.net/api/balance", post_data)
result = json.load(res)
print result

I get this results (sorry for the primitive formatting)
Code:
password=top-secret&user=12345
{u'error': u'Missing user and/or password POST parameters'}
(of course these are not my real userid and password, I get the same error with the real ones).

EDIT: Problem solved, se my post at the end.


Title: Re: Help with Bitstamp API
Post by: BCB on October 08, 2012, 03:18:41 PM
I'm going to guess you are sending a GET request and not a POST request ??


Title: Re: Help with Bitstamp API
Post by: picobit on October 08, 2012, 03:45:18 PM
I'm going to guess you are sending a GET request and not a POST request ??

No, Python's library use a POST when there are parameters (it is also possibly to use a GET, but then you need to append the parameters to the url yourself).  At least, that is what the docs say, but I am not sure if I can test it.


Title: Re: Help with Bitstamp API
Post by: BCB on October 08, 2012, 03:47:07 PM
I'm using PHP and when I send a GET request I get the same error you are showing, but when I send a post request it work.

Try removing urlencode


Title: [SOLVED] Re: Help with Bitstamp API
Post by: picobit on October 09, 2012, 12:04:30 PM
Problem solved.  I was missing a / at the end of the URL.  I guess the error message was kind of misleading :)