Skip to content

netrc auth broken when Session has base_url defined #348

@jeffcarrico

Description

@jeffcarrico

When base_url is defined on niquests.Session I think it needs to be included as part of the url sent to get_netrc_auth so that the netrc lookup has the complete url.

auth = get_netrc_auth(request.url)

Expected

Authorization header defined via netrc lookup when base_url defined on Session.

Actual Result

Authorization header was not added

Reproduction Steps

netrc file

machine httpbin.org
  login someuser
  password somepass
import niquests

# no authorization header
print(
    niquests.Session(base_url="https://httpbin.org")
    .get("headers")
    .raise_for_status()
    .json()
)

# authorization header
print(
    niquests.Session()
    .get("https://httpbin.org/headers")
    .raise_for_status()
    .json()
)

System Information

$ python -m niquests.help
{
  "charset_normalizer": {
    "version": "3.4.5"
  },
  "gil": true,
  "http1": {
    "h11": "0.16.0"
  },
  "http2": {
    "jh2": "5.0.10"
  },
  "http3": {
    "enabled": true,
    "qh3": "1.6.0"
  },
  "idna": {
    "version": "N/A"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.13.2"
  },
  "niquests": {
    "version": "3.18.1"
  },
  "ocsp": {
    "enabled": true
  },
  "platform": {
    "release": "6.1.131-143.221.amzn2023.x86_64",
    "system": "Linux"
  },
  "system_ssl": {
    "name": "OpenSSL 3.0.16 11 Feb 2025",
    "version": "30000100"
  },
  "urllib3.future": {
    "cohabitation_version": null,
    "version": "2.17.901"
  },
  "wassima": {
    "version": "2.0.5"
  },
  "websocket": {
    "enabled": false,
    "wsproto": null
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions