Closed finalblast closed 9 months ago
Hi, do you mean the one with a password?
Yes, that's correct. Proxy with username and password.
gpt-4 provides me with following code, could you validate it before it being included in the sources?
from http.client import HTTPSConnection
from base64 import b64encode
proxy_host = "proxy_host"
proxy_port = "proxy_port"
proxy_username = "username"
proxy_password = "password"
# Encode proxy username and password into base64
proxy_auth = b64encode(bytes(f'{proxy_username}:{proxy_password}', 'utf-8')).strip().decode('ascii')
# Set up original connection
conn = HTTPSConnection(proxy_host, proxy_port)
# Set up tunnel over the proxy to the actual address
conn.set_tunnel('www.somehost.com', headers={
'Proxy-Authorization': f'Basic {proxy_auth}'
})
# Now perform request as usual
conn.request('GET', '/index.html')
res = conn.getresponse()
data = res.read()
I relied on http.client
for a network level implementation, which is such a pain in the ass for any unusual movement (and mostly usual though), I planed to migrate to a requests
one, but it's not a subject of a nearest future, Q1 2024 most likely I believe.
{proxy_username}:{proxy_password} should be username and password in proxy configs. I think all should be good.
Great, thank you. Would you test a separate branch with these changes applied there to report whether it work or not?
@yaroslavyaroslav Yes, it works with these changes:
proxy_settings = self.settings.get('proxy')
if isinstance(proxy_settings, dict):
address = proxy_settings.get('address')
port = proxy_settings.get('port')
proxy_username = proxy_settings.get('username')
proxy_password = proxy_settings.get('password')
proxy_auth = b64encode(bytes(f'{proxy_username}:{proxy_password}', 'utf-8')).strip().decode('ascii')
if address and len(address) > 0 and port:
self.connection = HTTPSConnection(
host=address,
port=port
)
self.connection.set_tunnel("api.openai.com", headers={
'Proxy-Authorization': f'Basic {proxy_auth}'
})
else:
self.connection = HTTPSConnection("api.openai.com")
Don't forget to import at the top
from base64 import b64encode
I'll make this enhancement kinda soonish
@finalblast please review changes in #27.
Changes tested and all good.
Please add support for private proxy.