Last active
January 23, 2023 15:37
-
-
Save wolfv/ef49b98705aeed03dcf418ff20e3de83 to your computer and use it in GitHub Desktop.
Upload a file with Python, Requests and GraphQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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