Bitcoin Forum
June 23, 2024, 09:59:48 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: [Solved] Help with Bitstamp API  (Read 4295 times)
picobit (OP)
Hero Member
*****
Offline Offline

Activity: 547
Merit: 500


Decor in numeris


View Profile
October 08, 2012, 02:49:12 PM
Last edit: October 09, 2012, 12:07:04 PM by picobit
 #1

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.
BCB
CTG
VIP
Legendary
*
Offline Offline

Activity: 1078
Merit: 1002


BCJ


View Profile
October 08, 2012, 03:18:41 PM
 #2

I'm going to guess you are sending a GET request and not a POST request ??
picobit (OP)
Hero Member
*****
Offline Offline

Activity: 547
Merit: 500


Decor in numeris


View Profile
October 08, 2012, 03:45:18 PM
 #3

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.
BCB
CTG
VIP
Legendary
*
Offline Offline

Activity: 1078
Merit: 1002


BCJ


View Profile
October 08, 2012, 03:47:07 PM
 #4

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
picobit (OP)
Hero Member
*****
Offline Offline

Activity: 547
Merit: 500


Decor in numeris


View Profile
October 09, 2012, 12:04:30 PM
 #5

Problem solved.  I was missing a / at the end of the URL.  I guess the error message was kind of misleading Smiley
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!