[{"data":1,"prerenderedAt":73},["Reactive",2],{"/samples/python/requests":3,"related:nnSLvp8XHe":59},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"language":10,"library":8,"link":11,"body":12,"_type":54,"_id":55,"_source":56,"_file":57,"_extension":58},"/samples/python/requests","python",false,"","Requests","Requests is a popular Python HTTP library that provides a simple and elegant API for making HTTP requests and handling responses. It abstracts away the complexities of HTTP communication and provides features like automatic JSON parsing, session management, and response content decoding. requests is widely used for web scraping, API integration, and web development in Python.","Python","https://docs.python-requests.org/en/master/",{"type":13,"children":14,"toc":51},"root",[15,30,42],{"type":16,"tag":17,"props":18,"children":19},"element","p",{},[20,28],{"type":16,"tag":21,"props":22,"children":25},"a",{"href":11,"rel":23},[24],"nofollow",[26],{"type":27,"value":8},"text",{"type":27,"value":29}," is a popular Python HTTP library that provides a simple and elegant API for making HTTP requests and handling responses. It abstracts away the complexities of HTTP communication and provides features like automatic JSON parsing, session management, and response content decoding. requests is widely used for web scraping, API integration, and web development in Python.",{"type":16,"tag":31,"props":32,"children":36},"pre",{"className":33,"code":35,"language":5,"meta":7},[34],"language-python","import requests\n\ndef convert(api_key, params, endpoint='pdf'):\n    \"\"\"\n    We focused on making this function as simple as possible.\n    Since PDFShift is a REST API, we just need to send a\n    POST request to the endpoint by passing a set of custom parameters.\n    \n    Args:\n        api_key (str): Your API key.\n        params (dict): A dictionary containing the parameters\n                       you want to send to the API.\n        endpoint (str): The type of conversion you want to perform\n                        (pdf, png, jpg, webp)\n    \n    Returns:\n        bytes | dict: Either the binary content of the PDF\n                      or a dictionary containing the details\n                      when filename/webhook are passed\n    \"\"\"\n    \n    assert endpoint in ('pdf', 'png', 'jpg', 'webp')\n    \n    response = requests.post(\n        f'https://api.pdfshift.io/v3/convert/{endpoint}',\n        headers={'X-API-Key': api_key},\n        json=params\n    )\n    response.raise_for_status()\n    \n    if 'filename' in params or 'webhook' in params:\n        return response.json()\n    \n    return response.content\n",[37],{"type":16,"tag":38,"props":39,"children":40},"code",{"__ignoreMap":7},[41],{"type":27,"value":35},{"type":16,"tag":31,"props":43,"children":46},{"className":44,"code":45,"language":5,"meta":7},[34],"binary = convert('sk_XXXXXXXXXXXXXX', {'source': 'https://en.wikipedia.org/wiki/REST'})\nwith open('result.pdf', 'wb') as f:\n    f.write(binary)\n",[47],{"type":16,"tag":38,"props":48,"children":49},{"__ignoreMap":7},[50],{"type":27,"value":45},{"title":7,"searchDepth":52,"depth":52,"links":53},2,[],"markdown","content:samples:python:requests.md","content","samples/python/requests.md","md",[60,64,68,69],{"_path":61,"language":10,"library":62,"_id":63},"/samples/python/aiohttp","Aiohttp","content:samples:python:aiohttp.md",{"_path":65,"language":10,"library":66,"_id":67},"/samples/python/httplib2","Httplib2","content:samples:python:httplib2.md",{"_path":4,"language":10,"library":8,"_id":55},{"_path":70,"language":10,"library":71,"_id":72},"/samples/python/urllib3","Urllib3","content:samples:python:urllib3.md",1785426823457]