3 ms·
My most common use case here is to then want to hit the API from python, and adjust the params / url etc. Would love a "copy to python requests" button that g
by archiewood 3y ago
My most common use case here is to then want to hit the API from python, and adjust the params / url etc.
Would love a "copy to python requests" button that
grabs the headers
generates a boilerplate python snippet including the headers and the URL:
import requests
import json
url = '<endpoint>'
headers = {
'User-Agent': 'Mozilla/5.0 ...',
...
}
data = {
"page": 5,
"size": 28
...
}
response = requests.post(url, headers=headers, data=json.dumps(data))
if response.status_code == 200:
print(response.json())
else:
print(f"Error {response.status_code}: {response.text}")
- ea016 3y agoSteps to do so: - open the network console - right click on the request - click "copy as curl" - visit https://curlconverter.com/ https://curlconverter.com/ to convert to Python/Node/any language
- tilne 3y agoThank you for this. I didn’t know curlconverter existed.
- MurageKabui 3y agoI was to say this lol
- tech234a 3y agoAlso available as a VSCode extension that automatically matches the pasted content to the programming language used in the current file: https://marketplace.visualstudio.com/items?itemName=curlconverter.curlconverter https://marketplace.visualstudio.com/items?itemName=curlconv...
- verhovsky 3y agoI made a fork of the Chrome DevTools that adds "Copy as Python" to the right click menu of each request in the Network tab. You can tell Chrome to use a different version of the DevTools if you start it from the command line https://github.com/curlconverter/curlconverter/issues/64#issuecomment-1220330554 https://github.com/curlconverter/curlconverter/issues/64#iss...
- archiewood 3y agoThis is my current workflow, though with ChatGPT. I was just trying to save a few clicks
- novia 3y agoYou made your request sound important to implement when you already have a workaround that doesn't take very much time... This is why feature bloat is a thing
- kej 3y agoIt seems like you could combine this extension with some of the OpenAPI -> Python projects to get your desired result. (e.g. https://github.com/wy-z/requests-openapi https://github.com/wy-z/requests-openapi )
- yread 3y agowow what a perfect service to steal session cookies
- knowsuchagency 3y agoYou could take the OpenAPI json generated from this project and feed it to https://docs.scalar.com/swagger-editor https://docs.scalar.com/swagger-editor which generates boilerplate in several formats, including Python
- deleted 3y ago[deleted]
- gabrielsroka 3y ago1. You should almost always use requests.Session() instead of requests. It's faster, and can make the code shorter. 2. requests can dump to JSON for you by using json=, so you don't need a separate module. It'll even set the content-type header to application/json for you. import requests url = '<endpoint>' headers = { 'User-Agent': 'Mozilla/5.0 ...', ... } session = requests.Session() session.headers.update(headers) data = { "page": 5, "size": 28 ... } response = session.post(url, json=data) if response.status_code == 200: print(response.json()) else: print(f"Error {response.status_code}: {response.text}")
- prometheon1 3y agoYou could potentially go one step further and make Python classes that wrap the whole API automatically from the OpenAPI file: https://github.com/mom1/apiclient-pydantic-generator https://github.com/mom1/apiclient-pydantic-generator
- westurner 3y agoSeleniumIDE can record and save browser test cases to Python: https://github.com/SeleniumHQ/selenium-ide https://github.com/SeleniumHQ/selenium-ide awesome-test-automation/python-test-automation.md lists a number of ways to wrap selenium/webdriver and also playwright: https://github.com/atinfo/awesome-test-automation/blob/master/python-test-automation.md#web-ui-test-automation https://github.com/atinfo/awesome-test-automation/blob/maste... vcr.py, playback, and rr do [HTTP,] test recording and playback. httprunner can record and replay HAR. DevTools can save http requests and responses to HAR files. awesome-web-archiving lists a number of tools that work with WARC; but only har2warc: https://github.com/iipc/awesome-web-archiving/blob/main/README.md https://github.com/iipc/awesome-web-archiving/blob/main/READ...