3

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.

2
  • You don't need the json.dumps(), but you do need to make it a requests.post function call instead. Commented Oct 26, 2017 at 2:03
  • Thank you, I was careless with that, I need be more careful. Commented Oct 26, 2017 at 2:06

1 Answer 1

2

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)
Sign up to request clarification or add additional context in comments.

6 Comments

I think your params in the request should be data instead, since params are sent with the URL and stringified data goes in the body/data.
I tried switching things around but I still get the invalid parameter error, my guess is it has to do with the UnderOver I don't fully understand how to represent it >>> parameter = {"Bet": 10.0000000, "Payout":2.0, "Over": True, "ClientSeed": "CTThgTlac54qK2lahvLicrFlJsJmSIEkRMt4VcuN"} >>> response = requests.post(_url, json = parameter)
Sorry about the comment above, looks messy, but when I use data = parameters I get this error The request contains an entity body but no Content-Type header. The inferred media type 'application/octet-stream' is not supported for this resource.
I've edited to add a headers param. From your URL, is the coin you're betting on a coin called "PLAY"? And you didn't do parameters = json.dumps(parameter), you used paramter without the s.
You've been very helpful to me today, thank you very much, it's working now. I left the "UnderOver": True" the same, I guess T/F for under/over.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.