[{"data":1,"prerenderedAt":147},["Reactive",2],{"/guides/python/urllib3/accessing-secured-pages":3,"related:DTZWwgmPtR":65},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"language":10,"library":5,"property":11,"output":12,"related":13,"default":6,"body":16,"_type":60,"_id":61,"_source":62,"_file":63,"_extension":64},"/guides/python/urllib3/accessing-secured-pages","urllib3",false,"","Accessing secured pages","Learn how to access secured pages using Python and the urllib3 library. This guide offers detailed steps with code samples in Python and the urllib3 library, highlighting how you can acces page protected by basic authentication to convert them to PDF using PDFShift's API.","Python","auth","pdf",[14,15],"send-custom-http-headers","using-cookies",{"type":17,"children":18,"toc":57},"root",[19,27,40,52],{"type":20,"tag":21,"props":22,"children":23},"element","p",{},[24],{"type":25,"value":26},"text","In this guide, we'll show you how to access secured page (protected by basic authentication) using Python and the urllib3 library to convert them to PDF using PDFShift's API.",{"type":20,"tag":21,"props":28,"children":29},{},[30,32,38],{"type":25,"value":31},"When you're converting a document, you might want to access a secured page (protected by basic authentication) to convert it to PDF. This can be done by setting the ",{"type":20,"tag":33,"props":34,"children":36},"code",{"className":35},[],[37],{"type":25,"value":11},{"type":25,"value":39}," parameter to the request.",{"type":20,"tag":41,"props":42,"children":47},"pre",{"className":43,"code":45,"language":46,"meta":7},[44],"language-python","import urllib3, json, base64\n\n# You can get an API key at https://pdfshift.io\napi_key = 'sk_xxxxxxxxxxxx'\n\nparams = {\n    'source': 'https://www.example.com',\n    # You can set a basic authentication by passing the \"auth\" property which contains a username and password\n    'auth': {\n        'username': 'user',\n        'password': 'password'\n    }\n}\n\nhttp = urllib3.PoolManager()\nresponse = http.request(\n    'POST',\n    'https://api.pdfshift.io/v3/convert/pdf',\n    headers={\n        'Content-Type': 'application/json',\n        'X-API-Key': api_key\n    },\n    body=json.dumps(params).encode('utf-8')\n)\n\nif response.status != 200:\n    raise ValueError(f\"Request failed with status code {response.status}: {response.data.decode('utf-8')}\")\n\nwith open('result.pdf', 'wb') as f:\n    f.write(response.data)\n\nprint('The PDF document was generated and saved to result.pdf')\n","python",[48],{"type":20,"tag":33,"props":49,"children":50},{"__ignoreMap":7},[51],{"type":25,"value":45},{"type":20,"tag":21,"props":53,"children":54},{},[55],{"type":25,"value":56},"This allows you to protect your documents from any visitors while allowing PDFShift to access the page and convert it to PDF.",{"title":7,"searchDepth":58,"depth":58,"links":59},2,[],"markdown","content:guides:python:urllib3:accessing-secured-pages.md","content","guides/python/urllib3/accessing-secured-pages.md","md",[66,67,71,75,79,83,87,91,95,99,103,107,111,115,119,123,127,131,135,139,143],{"_path":4,"title":8,"language":10,"library":5,"_id":61},{"_path":68,"title":69,"language":10,"library":5,"_id":70},"/guides/python/urllib3/adding-a-custom-header-or-footer","Adding a custom header or footer","content:guides:python:urllib3:adding-a-custom-header-or-footer.md",{"_path":72,"title":73,"language":10,"library":5,"_id":74},"/guides/python/urllib3/adding-a-text-watermark","Adding a text watermark","content:guides:python:urllib3:adding-a-text-watermark.md",{"_path":76,"title":77,"language":10,"library":5,"_id":78},"/guides/python/urllib3/adding-an-image-watermark","Adding an image watermark","content:guides:python:urllib3:adding-an-image-watermark.md",{"_path":80,"title":81,"language":10,"library":5,"_id":82},"/guides/python/urllib3/avoid-conversion-on-error","Avoid the conversion on error when loading the document","content:guides:python:urllib3:avoid-conversion-on-error.md",{"_path":84,"title":85,"language":10,"library":5,"_id":86},"/guides/python/urllib3/convert-html-to-pdf-from-a-url","Convert an HTML document to PDF from a URL","content:guides:python:urllib3:convert-html-to-pdf-from-a-url.md",{"_path":88,"title":89,"language":10,"library":5,"_id":90},"/guides/python/urllib3/convert-html-to-pdf-from-raw-html","Convert an HTML document to PDF from raw HTML","content:guides:python:urllib3:convert-html-to-pdf-from-raw-html.md",{"_path":92,"title":93,"language":10,"library":5,"_id":94},"/guides/python/urllib3/define-a-time-limit","Define a time limit","content:guides:python:urllib3:define-a-time-limit.md",{"_path":96,"title":97,"language":10,"library":5,"_id":98},"/guides/python/urllib3/exporting-only-a-specific-set-of-pages","Exporting only a specific set of pages","content:guides:python:urllib3:exporting-only-a-specific-set-of-pages.md",{"_path":100,"title":101,"language":10,"library":5,"_id":102},"/guides/python/urllib3/generate-a-document-with-full-height","Generate a document with full height","content:guides:python:urllib3:generate-a-document-with-full-height.md",{"_path":104,"title":105,"language":10,"library":5,"_id":106},"/guides/python/urllib3/loading-css-from-a-string","Loading CSS from a string","content:guides:python:urllib3:loading-css-from-a-string.md",{"_path":108,"title":109,"language":10,"library":5,"_id":110},"/guides/python/urllib3/loading-css-from-a-url","Loading CSS from a URL","content:guides:python:urllib3:loading-css-from-a-url.md",{"_path":112,"title":113,"language":10,"library":5,"_id":114},"/guides/python/urllib3/loading-javascript-from-a-string","Loading Javascript from a string","content:guides:python:urllib3:loading-javascript-from-a-string.md",{"_path":116,"title":117,"language":10,"library":5,"_id":118},"/guides/python/urllib3/loading-javascript-from-a-url","Loading Javascript from a URL","content:guides:python:urllib3:loading-javascript-from-a-url.md",{"_path":120,"title":121,"language":10,"library":5,"_id":122},"/guides/python/urllib3/protecting-the-generated-pdf","Protecting the generated PDF","content:guides:python:urllib3:protecting-the-generated-pdf.md",{"_path":124,"title":125,"language":10,"library":5,"_id":126},"/guides/python/urllib3/receive-a-webhook-event","Receive a webhook event","content:guides:python:urllib3:receive-a-webhook-event.md",{"_path":128,"title":129,"language":10,"library":5,"_id":130},"/guides/python/urllib3/save-your-pdf-online-and-get-back-a-url","Save your PDF online and get back a URL","content:guides:python:urllib3:save-your-pdf-online-and-get-back-a-url.md",{"_path":132,"title":133,"language":10,"library":5,"_id":134},"/guides/python/urllib3/save-your-pdf-to-your-amazon-s3-bucket","Save your PDF to your Amazon S3 Bucket","content:guides:python:urllib3:save-your-pdf-to-your-amazon-s3-bucket.md",{"_path":136,"title":137,"language":10,"library":5,"_id":138},"/guides/python/urllib3/send-custom-http-headers","Send custom HTTP headers","content:guides:python:urllib3:send-custom-http-headers.md",{"_path":140,"title":141,"language":10,"library":5,"_id":142},"/guides/python/urllib3/using-cookies","Using cookies to convert HTML documents to PDF","content:guides:python:urllib3:using-cookies.md",{"_path":144,"title":145,"language":10,"library":5,"_id":146},"/guides/python/urllib3/waiting-for-a-custom-element-to-be-ready","Waiting for a custom element to be ready","content:guides:python:urllib3:waiting-for-a-custom-element-to-be-ready.md",1785426833848]