Ask coding questions

← Back to all posts
Graphql problems (maybe not but with the python requests module)
h
ch1ck3n (1576)

I used ryanadev's iphone cycle thing script and tried to do it with python.

this is my code:

import requests
import json

url = 'https://staging.repl.it/graphql'
payload = {'query': '{ userByUsername{username: "ch1ck3n" { karma } } }'}
headers = {'X-Requested-With': 'My stupid script', 'Referrer': "https://repl.it/"}

r = requests.post(url, data=json.dumps(payload), headers=headers)

print(r.text)

this basically prints out my cycles.

but then I see this response.

POST body missing. Did you forget use body-parser middleware?

i expected my number of cycles, I don't know what's wrong.

Answered by Coder100 (16842) [earned 5 cycles]
View Answer
Comments
hotnewtop
Coder100 (16842)

ez

import requests
import json

url = 'https://staging.repl.it/graphql'
payload = {'query': 'query { userByUsername(username: "ch1ck3n") { karma } }'}
headers = {'X-Requested-With': 'My stupid script', 'Referrer': "https://repl.it/", 'content-type': 'application/json'}

r = requests.post(url, data=json.dumps(payload), headers=headers)

print(r.text)
ch1ck3n (1576)

@Coder100 ohwaittadaputa how-did-you-do-that

Coder100 (16842)

lol you might want to learn graphql @ch1ck3n

Coder100 (16842)

you forgot to add 'Content-Type': 'application/json' to the headers

ch1ck3n (1576)

@Coder100 OH FRICC I DELETED THAT LINE CUZ I DIDNT KNOW WHAT IT DOES

ch1ck3n (1576)

@Coder100 ok wait now i get this

{"errors":[{"message":"Syntax Error: Expected Name, found String \"ch1ck3n\"","locations":[{"line":1,"column":28}],"extensions":{"code":"GRAPHQL_PARSE_FAILED"}}]}

and here's my code

https://repl.it/@ch1ck3n/Testing-graphql#main.py

ch1ck3n (1576)

@Coder100 It treats the escape characters as a literal string

Coder100 (16842)

oh yeah also your graphql isn't valid
but wdym @ch1ck3n