Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!bcyclone03.am1.xlned.com!bcyclone03.am1.xlned.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'wrapped': 0.07; 'library?': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'tuple.': 0.09; 'url:github': 0.09; 'headers': 0.15; 'literals': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:requests': 0.16; 'pass': 0.22; 'tried': 0.24; 'import': 0.24; 'header': 0.24; 'requests': 0.25; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'anyone': 0.32; 'username': 0.33; 'i.e.': 0.35; 'but': 0.36; 'to:addr:python- list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'expect': 0.37; 'received:org': 0.37; 'charset:us-ascii': 0.37; 'anything': 0.38; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'received:de': 0.40; 'ever': 0.60; 'real': 0.62; 'subject:skip:A 10': 0.63; 'url:user': 0.63; 'received:217': 0.66; 'online': 0.71; 'subject:Using': 0.84; 'url:api': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: dieter Subject: Re: Using requests with an Authorization header? Date: Wed, 29 Jul 2015 08:01:54 +0200 References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Gmane-NNTP-Posting-Host: pd9e0acb6.dip0.t-ipconnect.de User-Agent: Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux) Cancel-Lock: sha1:sSnEAga7uyQ4bAcK2BZ6VF5mbqQ= X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1438149722 news.xs4all.nl 2895 [2001:888:2000:d::a6]:35060 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 3553 X-Received-Body-CRC: 4010961733 Xref: csiph.com comp.lang.python:94721 devnzyme1@use.startmail.com writes: > Has anyone ever used an authorization header with the requests library? I tried using: > > >>>> from requests.auth import HTTPBasicAuth >>>> requests.get('https://api.github.com/user', auth=HTTPBasicAuth('user', 'pass') > > from their docs online but that's not working and I don't see anything about authorization headers We are using it like this (successfully): requests.post(url, data=data, params=params, auth=(user, passwd), timeout=timeout, verify=verify, headers=jsonHeaders, ) i.e. "user" and "password" are not wrapped into an "HTTPBasicAuth" but directly passed as tuple. However, I expect that it would also work with an "HTTPBasicAuth" wrapping. Note that you must pass the real username and password, not the literals "'user'" and "'pass'".