Skip to content

Instantly share code, notes, and snippets.

@wolfv
Last active January 23, 2023 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolfv/ef49b98705aeed03dcf418ff20e3de83 to your computer and use it in GitHub Desktop.
Save wolfv/ef49b98705aeed03dcf418ff20e3de83 to your computer and use it in GitHub Desktop.
Upload a file with Python, Requests and GraphQL
import requests
import json
url = 'http://localhost:3001/api/graphql'
cookies = {}
mutation = '''mutation($file: Upload!) {
uploadEnv(environmentFileUpload: $file) {
id
}
}'''
variables = {
"file": None,
}
data = {
'query': mutation,
'variables': variables
}
response = requests.post(url, data = {
"operations": json.dumps(data),
"map": json.dumps({ "0": ["variables.file"] })
},
files = {
"0" : open("/path/to/environment.yml", "rb")
},
cookies=cookies
)
print(response)
print(response.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment