When a screenshot API returns image data directly, save it with Python in binary mode: check the HTTP status, then write response.content to a file opened with wb. First confirm the API’s response format: some endpoints return a redirect or JSON containing an image URL instead of image bytes.
Save a direct image response with Requests
For a small screenshot returned as raw bytes, use requests.get(), check for an HTTP error, and write the bytes to disk. This example assumes the endpoint accepts a GET request with a url query parameter and returns PNG data; replace those details with the screenshot provider’s documented request format.
As an Amazon Associate I earn from qualifying purchases.
import requests
response = requests.get(
"SCREENSHOT_ENDPOINT",
params={"url": "https://example.com"},
timeout=30,
)
response.raise_for_status()
with open("screenshot.png", "wb") as image_file:
image_file.write(response.content)
The 30-second timeout is an example, not a universal setting. Choose a finite timeout appropriate to your service and workload. Requests exposes response.content as bytes; raise_for_status() prevents an HTTP error response from being silently saved as though it were a screenshot. See the Requests API reference and its Quickstart.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Keep credentials out of source code
If the API requires a key, pass it using the provider’s documented authentication method. Keep secrets in an environment variable or secret store rather than committing them to a script or repository. The authentication scheme is provider-specific.
#1 Best Overall
Identify what the API actually returns
Do not choose the save logic or filename based only on the word “screenshot” in the endpoint. Check the provider’s documentation and, where relevant, the response status, headers, and body.
- Raw image bytes: Save the response body as bytes, as in the first example.
- Redirect to an image: Follow the provider’s documented redirect behavior and save the final image response. Confirm that your client follows redirects as expected.
- JSON with an image URL: Parse the JSON, extract the documented URL field, then make a second request and save that response’s bytes. Do not save the JSON response with a
.pngextension.
As one provider-specific example, Screenshot API documents JSON by default and a redirect=1 option for image or PDF output; its Python example reads a screenshotUrl from JSON. That is not a universal screenshot API contract. See its REST API documentation.
Rank #2
Stream large screenshots to disk
For a potentially large response, stream chunks to the file instead of retaining the entire body in memory. Requests recommends iter_content() for streamed downloads; it handles gzip and deflate transfer encodings. The chunk size below is a code choice, not a performance benchmark.
import requests
with requests.get(
"SCREENSHOT_ENDPOINT",
params={"url": "https://example.com"},
stream=True,
timeout=30,
) as response:
response.raise_for_status()
with open("screenshot.png", "wb") as image_file:
for chunk in response.iter_content(chunk_size=64 * 1024):
if chunk:
image_file.write(chunk)
Use a finite timeout appropriate to the provider and workload. A timeout is not a guarantee that a screenshot will finish within that duration: the provider’s rendering time and network conditions matter. Requests’ streaming guidance is in the Quickstart.
Match the file extension to the image format
A file extension does not convert the response. If the API returns JPEG bytes but the file is named screenshot.png, the contents remain JPEG. Use the format requested from the provider, if supported, or inspect Content-Type and the provider’s documentation before choosing an extension. Requests exposes response headers through response.headers; the endpoint’s exact output format cannot be inferred without its documentation.
Use Python’s standard library if you do not want Requests
urllib.request is a standard-library option for opening URLs. Use the provider’s actual endpoint, parameters, and authentication, and preserve the same essentials: handle HTTP errors, treat image payloads as bytes, and distinguish image data from JSON or redirects. See the Python 3.13 urllib.request documentation.
Common problems and fixes
- The saved file is not an image: The server may have returned an error or JSON. Check the status with
raise_for_status(), inspectContent-Type, and verify the documented response shape before writing. - The image opens in the wrong application or not at all: The extension may not match the returned format. Check the provider’s format setting and response headers; renaming the file does not convert it.
- The request hangs or fails on slow captures: Set a finite timeout suitable for the service and workload. If it expires, adjust it based on the provider’s documented behavior and your application’s needs.
- The response is JSON rather than an image: Parse the documented JSON field containing the screenshot URL, then download that URL in a second request.
- The output is incomplete or memory use is high: For large responses, use
stream=Trueand write non-empty chunks fromiter_content(). - The API rejects the request: Check its required HTTP method, authentication, parameter names, and response mode. These details vary by provider; the illustrative request above is not a universal API format.
Or skip the browser setup
ScreenshotNeo returns an image or PDF from one GET request. For a PNG, JPEG, or WebP screenshot, use its documented format parameter as needed; this basic example saves the response body as WebP:
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11import requests
r = requests.get(
"https://api.screenshotneo.com/v1/shot",
params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
timeout=90,
)
open("shot.webp", "wb").write(r.content)
See the ScreenshotNeo documentation for request parameters and response details. It accepts cookie and consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for AI agents and other MCP clients. The Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 screenshots.
Learn about ScreenshotNeo, or sign up free for 1,000 screenshots a month with no card.
Best Value
Frequently Asked Questions
Does writing a screenshot response with wb convert it to PNG?
No. Binary mode preserves the response bytes; it does not change their format. Match the extension to the returned format.
Should I use response.content or iter_content()?
Use response.content for a small response you can keep in memory. For a potentially large download, stream with stream=True and write chunks from iter_content().
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




