Reputation: 117
I'm new to the programming API's, I'm trying to write my bot to run on a site and this is the doc to the API Crypto-games API doc site but I get the 400 error
on execution for the place bet command and the error won't print out the error content, just the error code. Here is what they gave on their site
URL: /v1/placebet/:coin/:key
{ "Bet": 0.00001024, "Payout": 2.0, "UnderOver": true, "ClientSeed": "somerandomseed" }
UnderOver is target result. Example: < 49.600 or > 50.399`
And here's a sample Javascript they gave
var input = { Bet: 0.00001024, Payout: 2.0, UnderOver: true,
ClientSeed: "somerandomseed" };
$.ajax({
url: "https://api.crypto-games.net/v1/placebet/BTC/7Ii8vdPBUBfTPHcuzkHuhftkGD43iWwbFkdwBQa7GL8R4AwBr3",
data: JSON.stringify(input),
dataType: "json",
contentType: "application/json",
type: "POST",
success: function (r) {
console.log(r);
}
});
here is the Python code I wrote to run the placebet command
import requests
import json
parameter = {"Bet": 10.0000000, "Payout":2.0, " >50.399": True, "ClientSeed": "CTThgTlac54qK2lahvLicrFlJsJmSIEkRMt4VcuN"}
parameters = json.dumps(parameter)
response = requests.get("https://api.crypto-games.net/v1/placebet/PLAY/XxxMyAPIHerexxX", params = parameters)
print(response.content)
print(response.status_code)
I tried running it without the json.dumps()
but I still get the same output. Can someone point out what I'm doing wrong, all criticism and suggestions are welcome.
Upvotes: 3
Views: 168
Reputation: 15962
According to the Place bet docs (and in the example code pasted), it's supposed to be a POST
request, not GET
.
response = requests.post(...)
Edit: I think your params
in the request should be data
instead, since params are sent with the URL and stringified data goes in the request body/data. (The json.dumps()
is correct.)
parameters = json.dumps(parameter)
response = requests.post("https://api.crypto-games.net/v1/placebet/PLAY/XxxMyAPIHerexxX",
data=parameters)
And you can send JSON data in the body without it if you're on a more recent version of :requests
>>> url = 'https://api.github.com/some/endpoint' >>> payload = {'some': 'data'} >>> r = requests.post(url, json=payload)
Edit 2:
"UnderOver": true
is mandatory in the data to be sent. Their examples are unclear about how that is supposed to be translated to a number. I think that's the Bet
value (so +/- the Bet amount). So try:
parameter = {"Bet": 10.0000000, "Payout":2.0, "UnderOver": True, "ClientSeed": "CTThgTlac54qK2lahvLicrFlJsJmSIEkRMt4VcuN"}
Also, don't use requests.post(url, json=payload)
method because it translates Python's True
to the js string "True"
instead of js boolean true
. So stick with parameters = json.dumps(parameter)
method, but still as data.
Wrt "Content-Type" error, add this to your request:
headers = {'Content-Type': 'application/json'}
response = requests.post("https://api.crypto-games.net/v1/placebet/PLAY/XxxMyAPIHerexxX",
data=parameters,
headers=headers)
Upvotes: 2