Python

Submit a request with the Python standard library.

import json
import os
import uuid
from urllib.request import Request, urlopen

base = "https://api.runharvester.com/api/v1/data"
headers = {
    "X-API-Key": os.environ["RUNHARVESTER_API_KEY"],
    "Content-Type": "application/json",
    "Idempotency-Key": str(uuid.uuid4()),
}
payload = json.dumps({"url": "https://example.com", "mode": "auto", "proxy": "random"}).encode()

request = Request(f"{base}/requests", data=payload, headers=headers, method="POST")
with urlopen(request) as response:
    request_data = json.load(response)

result_request = Request(f"{base}/requests/{request_data['id']}/result", headers=headers)
with urlopen(result_request) as response:
    result = json.load(response)

Add polling and explicit retry handling before using this in a worker.

Last updated on