Kaggle / Kaggle/kaggle-cli

connect behind a proxy with authentication

Open
#43 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
7.5k
Forks
1.4k
Avg merge
3d 15h
Merged PRs (30d)
11

Description

Hi, there. I was using kaggle-api behind a proxy with authentication. After I set kaggle configs with correct credentials using:
```bash
kaggle config set -n proxy -v http://username:password@host:port
```
and ran any commands that require http connection, I got errors like:

WARNING Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: **407 authenticationrequired**',))'

After some browsing of the source code, I think the problem was due to the proxy authentication info not correctly conveyed to the client settings. I managed to get my connection working by modifying rest.py as follows (starting line 102, added `proxy_headers`):
```python
if configuration.proxy:
if '@' in configuration.proxy:
proxy_url = configuration.proxy.split('://')[0] + '://' + configuration.proxy.split('@')[-1]
proxy_headers = urllib3.make_headers(proxy_basic_auth='@'.join(configuration.proxy.split('://', 1)[1].split('@')[:-1]))
else:
proxy_url = configuration.proxy
proxy_headers = None
self.pool_manager = urllib3.ProxyManager(
num_pools=pools_size,
maxsize=maxsize,
cert_reqs=cert_reqs,
ca_certs=ca_certs,
cert_file=configuration.cert_file,
key_file=configuration.key_file,
proxy_url=proxy_url,
proxy_headers=proxy_headers,
**addition_pool_args
)
```
Though I find that in the original code `urllib3.ProxyManager` with `proxy_url=configuration.proxy` can parse my proxy link into:
```python
urllib3.util.url.Url(scheme='http', auth='username:password', host='host', port=port, path=None, query=None, fragment=None)
```
For your reference, the [urllib3 docs](http://urllib3.readthedocs.io/en/latest/reference/#urllib3.poolmanager.ProxyManager) also indicates using `proxy_headers` for proxy authentication.

I noticed files like rest.py are generated by swagger-codegen and am not sure whether my modifications are appropriate. Look forward to your reply!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.