Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we use auth proxies? #28

Closed
cosmicsplendor opened this issue Dec 4, 2023 · 8 comments
Closed

Can we use auth proxies? #28

cosmicsplendor opened this issue Dec 4, 2023 · 8 comments
Labels
dependency bug Issue with a dependency

Comments

@cosmicsplendor
Copy link

How could we accomplish something like this using hrequests?

import requests

proxies = {
   'http': 'http://proxy.example.com:8080',
   'https': 'http://proxy.example.com:8081',
}

response = requests.get('http://httpbin.org/ip', proxies=proxies auth=('USERNAME', 'PASSWORD'))
@cosmicsplendor
Copy link
Author

This library supports normal http proxies (example: http://proxy.example.com:8080).

But I couldn't get it to work with proxies that require username password authentication (example: http://username:[email protected]:8080).

I'd appreciate if you could me know whether and how this could be achieved.

@Cosmicoppai
Copy link

@cosmicsplendor hey, are able to find any workaround with this lib?

@ilyazub
Copy link

ilyazub commented Jan 9, 2024

Related to bogdanfinn/tls-client#66.

@cosmicsplendor
Copy link
Author

@cosmicsplendor hey, are able to find any workaround with this lib?

I haven't been able to get this to work yet. Will update here if I find a workaround.

@cosmicsplendor
Copy link
Author

this works, but you have to rely on requests library to create session:

import requests
import hrequests

proxies = {
'http': 'http://USERNAME:[email protected]',
'https': 'http://USERNAME:[email protected]'
}

session = requests.Session()
session.proxies.update(proxies)

response = hrequests.get('http://httpbin.org/ip', session=session)
print(response.text)

@ilyazub
Copy link

ilyazub commented Jan 10, 2024

@cosmicsplendor What hrequests version do you use? It worked for me with v0.7.1.

>>> import hrequests
>>> response = hrequests.get('http://httpbin.org/ip', debug=True, verify=False, proxies=proxies)
raw request bytes sent over wire: 344 (0 kb)
headers on request:
map[Accept:[*/*] Accept-Encoding:[gzip, deflate, br] Accept-Language:[en-US;q=0.5,en;q=0.3] Connection:[keep-alive] Header-Order::[] Host:[httpbin.org] Referer:[https://google.com] Upgrade-Insecure-Requests:[1] User-Agent:[Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.6167.0 Safari/537.36]]
cookies on request:
[]
headers on response:
map[Access-Control-Allow-Credentials:[true] Access-Control-Allow-Origin:[*] Connection:[keep-alive] Content-Length:[31] Content-Type:[application/json] Date:[Wed, 10 Jan 2024 10:41:27 GMT] Server:[gunicorn/19.9.0]]
cookies on response:
[]
requested http://httpbin.org/ip : status 200
response body payload: {
  "origin": "...omitted..."
}

raw response bytes received over wire: 260 (0 kb)
>>> hrequests.__version__
'0.7.1'

@cosmicsplendor
Copy link
Author

Mine is v0.7.1 too. I tried hard, but could not make it work. Normal proxies work fine, but when I try authentication, it always fails.

daijro added a commit that referenced this issue Feb 4, 2024
- Bump to tls-client to 1.7.2
- Detect & override encoding (#24, #31, #32). Works by encoding non-UTF-8 responses in Base64, then sending to Python. Requires faust-cchardet for encoding detection.
- Add support for auth http proxies & https (#19)
- Add support for socks5 (#28)
- `proxies` keyword deprecated in favor of `proxy`
- Support for Python 3.7-3.8 (#30)
- Added certificate pinning
- Added option to disable IPv6
- More descriptive ClientException errors
- Added proxy support for Firefox and Chromium
- Added `raise_exception` parameter in HTML parser's .find and .find_all
- Updated README for 0.8.0-beta.2
- (Hopefully) Fixed crashing issue when importing. Open ports are now found by go's http api rather than python sockets.
@daijro daijro added the dependency bug Issue with a dependency label Feb 5, 2024
@HOSEENJ
Copy link

HOSEENJ commented Mar 11, 2024

to use proxy in sessions you can do like this:
session = hrequests.Session()
session.proxy = 'http://username:password@host:port'

@daijro daijro closed this as completed Mar 29, 2024
@daijro daijro mentioned this issue Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependency bug Issue with a dependency
Projects
None yet
Development

No branches or pull requests

5 participants