<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>python on dominik.suess.wtf</title><link>https://dominik.suess.wtf/filetags/python/</link><description>Recent content in python on dominik.suess.wtf</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Sun, 05 Jul 2026 15:46:24 +0200</lastBuildDate><atom:link href="https://dominik.suess.wtf/filetags/python/index.xml" rel="self" type="application/rss+xml"/><item><title>Python requests lib silently drops custom auth header</title><link>https://dominik.suess.wtf/notes/20260626t115405/</link><pubDate>Fri, 26 Jun 2026 00:00:00 +0000</pubDate><guid>https://dominik.suess.wtf/notes/20260626t115405/</guid><description>&lt;p&gt;
While trying out the &lt;a href="https://cartography-cncf.github.io/cartography/"&gt;cartography&lt;/a&gt; project (in particular their github module), I was confronted with weird errors around bad authorization tokens.&lt;/p&gt;
&lt;p&gt;
On the surface, this code looks correct:&lt;/p&gt;
&lt;div class="src src-python"&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#fff;background-color:#000;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;response &lt;span style="color:#00d3d0"&gt;=&lt;/span&gt; requests&lt;span style="color:#00d3d0"&gt;.&lt;/span&gt;get(
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#79a8ff"&gt;&amp;#34;https://api.github.com/rate_limit&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; headers&lt;span style="color:#00d3d0"&gt;=&lt;/span&gt;{&lt;span style="color:#79a8ff"&gt;&amp;#39;Authorization&amp;#39;&lt;/span&gt;: authHeader},
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
However, the &lt;a href="https://docs.python-requests.org/en/latest/user/quickstart/#custom-headers:~:text=Authorization%20headers%20set%20with%20headers%3D%20will%20be%20overridden%20if%20credentials%20are%20specified%20in%20%2Enetrc%2C%20which%20in%20turn%20will%20be%20overridden%20by%20the%20auth%3D"&gt;requests library silently prefers credentials from &lt;code&gt;.netrc&lt;/code&gt; if it exists&lt;/a&gt; 🤯&lt;/p&gt;
&lt;p&gt;
This file still had expired credentials for &lt;code&gt;api.github.com&lt;/code&gt; in my case from ages
ago when I tried out &lt;a href="https://github.com/magit/forge"&gt;magit forge&lt;/a&gt;. Clearing that file solved all issues for me.&lt;/p&gt;</description></item></channel></rss>