psf / requests

A simple, yet elegant, HTTP library.
https://requests.readthedocs.io/en/latest/
Apache License 2.0
52.19k stars 9.33k forks source link

Possible .get bug in version 2.32.3 #6753

Closed mhenrichsen closed 4 months ago

mhenrichsen commented 4 months ago

When executing a file named ast.py which .get(url) it fails with AttributeError: partially initialized module 'requests' has no attribute 'get' (most likely due to a circular import)

Expected Result

To fetch the contents.

  1. Create a file named ast.py

x = requests.get('https://w3schools.com')
print(x.status_code)
  1. rename the file for success.

System Information

$ python -m requests.help
{
  "chardet": {
    "version": null
  },
  "charset_normalizer": {
    "version": "3.3.2"
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "3.7"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.12.4"
  },
  "platform": {
    "release": "23.2.0",
    "system": "Darwin"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.32.3"
  },
  "system_ssl": {
    "version": "30300010"
  },
  "urllib3": {
    "version": "2.2.1"
  },
  "using_charset_normalizer": true,
  "using_pyopenssl": false
}
nateprewitt commented 4 months ago

ast is a module in the standard library. Shadowing commonly used modules will lead to breakages in most Python libraries. This isn't something we can address in Requests, this is a fundamental of the language.

mhenrichsen commented 4 months ago

@nateprewitt thanks for letting me know. It was driving me crazy.