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

SNOW-810810: AttributeError when using SOCKS5 Proxy #1550

Closed
stan-janssen opened this issue May 8, 2023 · 10 comments · Fixed by #1551
Closed

SNOW-810810: AttributeError when using SOCKS5 Proxy #1550

stan-janssen opened this issue May 8, 2023 · 10 comments · Fixed by #1551
Assignees
Labels

Comments

@stan-janssen
Copy link
Contributor

stan-janssen commented May 8, 2023

Please answer these questions before submitting your issue. Thanks!

  1. What version of Python are you using?
Python 3.9.16 (main, May  8 2023, 20:48:22) 
[GCC 11.3.0]
  1. What operating system and processor architecture are you using?
Linux-5.19.0-41-generic-x86_64-with-glibc2.35
  1. What are the component versions in the environment (pip freeze)?

    Replace with the output of python -m pip freeze

  2. What did you do?

Attempt to connect to Snowflake through a SOCKS5 proxy:

Use a minimal SOCKS5 proxy. From a second computer (computer2), open a SOCKS5 proxy on computer1

user@computer2:~$ ssh -R 1080 user@computer1.local

On computer1:

HTTPS_PROXY="socks5://localhost:1080" python3 -c "import snowflake.connector; snowflake.connector.connect(...)"
  1. What did you expect to see?

The above test results in:

  File "/home/stan/Ontwikkeling/snowflake-connector-python/src/snowflake/connector/network.py", line 1042, in _request_exec
    raw_ret = session.request(
  File "/home/stan/Ontwikkeling/snowflake-connector-python/src/snowflake/connector/vendored/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/stan/Ontwikkeling/snowflake-connector-python/src/snowflake/connector/vendored/requests/sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "/home/stan/Ontwikkeling/snowflake-connector-python/src/snowflake/connector/vendored/requests/adapters.py", line 455, in send
    conn = self.get_connection(request.url, proxies)
  File "/home/stan/Ontwikkeling/snowflake-connector-python/src/snowflake/connector/network.py", line 274, in get_connection
    proxy_manager.proxy_headers["Host"] = parsed_url.hostname
AttributeError: 'SOCKSProxyManager' object has no attribute 'proxy_headers'

This is because the SOCKSProxyManager is a subclass of PoolManager Which does not have the property proxy_headers. It does have a property headers.

I modified the code to not set the header when using a SOCKS5 proxy, which seems to work. The connection succeeds over the SOCKS5 proxy. It also works if I set the headers property instead of the proxy_headers property.

I offer a pull request for the first solution (not setting the proxy_headers when using a SOCKS5 proxy), but I leave it up to someone more knowledgable to decide whether this is the desired solution to this.

@github-actions github-actions bot changed the title AttributeError when using SOCKS5 Proxy SNOW-810810: AttributeError when using SOCKS5 Proxy May 8, 2023
@sfc-gh-aling
Copy link
Collaborator

thanks for the feedback and the pull request! we will take a look!

@vajeeAtt
Copy link

Hey everyone, I'm facing the same issue with the missing attribute. Is there any reason why this is not merged, I couldn't find any other resolution for this issue.

@sfc-gh-achandrasekaran
Copy link
Contributor

We will review this PR next week. FYI @sfc-gh-aling

@vajeeAtt
Copy link

Thank you

@vajeeAtt
Copy link

We will review this PR next week. FYI @sfc-gh-aling

Is there anything I can do to help to move this further

@vajeeAtt
Copy link

@sfc-gh-aling , any updates on this? thank you

@gpgn
Copy link

gpgn commented Jul 28, 2023

Running into this as well, would be great if this could be merged soon 👍

@gpgn
Copy link

gpgn commented Jul 31, 2023

As a temporary workaround using PySocks works:

import socks
import socket

socks.set_default_proxy(**{
    "proxy_type": socks.SOCKS5,
    "addr": os.environ["PROXY_ADDR"],
    "username": os.environ["PROXY_USERNAME"],
    "password": os.environ["PROXY_PASSWORD"],
})
socket.socket = socks.socksocket

with snowflake.connector.connect(...) as con:
    cursor = con.cursor()

But this is no fix for other solutions that rely on the environment variables.

@vajeeAtt
Copy link

vajeeAtt commented Aug 3, 2023

@sfc-gh-aling I would like to know if there are any changes needed to promote this issue, thanks.

@sfc-gh-aling
Copy link
Collaborator

We just merged the PR which shall fix the issue and it will be carried in our next release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants