Created
April 27, 2023 12:13
-
-
Save thevickypedia/dfe0a0668a726267c7e1d99fc8bdfc8b to your computer and use it in GitHub Desktop.
Convert a python request to curl (without actually making a request)
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
SS_HEADERS = { | |
"Content-Type": "text/plain" | |
} | |
def check(response): | |
req = response.prepare() | |
command = "curl -X {method} \\\n -H {headers} \\\n -d '{data}' \\\n '{uri}'" | |
method = req.method | |
uri = req.url | |
data = req.body | |
headers = SS_HEADERS or req.headers | |
headers = ['"{0}: {1}"'.format(k, v) for k, v in headers.items()] | |
headers = "\\\n -H ".join(headers) | |
return command.format(method=method, headers=headers, data=data, uri=uri) | |
def checker(): | |
import requests | |
response = requests.Request( | |
url=f"http://localhost:5002/api/tts", | |
headers=SS_HEADERS, params={"voice": "en-us_northern_english_male-glow_tts", | |
"vocoder": "medium"}, data="Welcome to the world of speech synthesis", | |
) | |
return response | |
if __name__ == '__main__': | |
print(check(checker()) + " \\\n --output temp.wav && open temp.wav") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment