Repository navigation
Closed as not planned
Description
Description of the problem, including code/CLI snippet
I have to access our gitlab server on port 7443, but urllib3 tries on 443 and I can't change the port.
How can I change the port?
My code (I had to modify hostname):
GITLAB_URL = 'https://foo.bar'
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
gl = gitlab.Gitlab(GITLAB_URL, private_token=GITLAB_TOKEN, ssl_verify=False)
projects = gl.projects.list(all=True)
The error in CLI (I had to modify username and hostname):
Traceback (most recent call last):
File "C:\Users\foo\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connection.py", line 159, in _new_conn
conn = connection.create_connection(
File "C:\Users\foo\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\util\connection.py", line 84, in create_connection
raise err
File "C:\Users\foo\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\util\connection.py", line 74, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\foo\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 670, in urlopen
httplib_response = self._make_request(
File "C:\Users\foo\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 381, in _make_request
self._validate_conn(conn)
File "C:\Users\foo\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 978, in _validate_conn
conn.connect()
File "C:\Users\foo\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connection.py", line 309, in connect
conn = self._new_conn()
File "C:\Users\foo\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connection.py", line 171, in _new_conn
raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x000002033C9897C0>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\foo\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\adapters.py", line 440, in send
resp = conn.urlopen(
File "C:\Users\foo\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 726, in urlopen
retries = retries.increment(
File "C:\Users\foo\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\util\retry.py", line 446, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='foo.bar', port=443):
Max retries exceeded with url: /api/v4/projects?membership=false&order_by=created_at&owned=false&page=2&per_page=20&simple=false&sort=desc&starred=false&statistics=false&with_custom_attributes=false&with_issues_enabled=false&with_merge_requests_enabled=false
(Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000002033C9897C0>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "../checkout.py", line 29, in <module>
projects = gl.projects.list(all=True)
File "C:\Users\foo\AppData\Local\Programs\Python\Python38\lib\site-packages\gitlab\exceptions.py", line 311, in wrapped_f
return f(*args, **kwargs)
File "C:\Users\foo\AppData\Local\Programs\Python\Python38\lib\site-packages\gitlab\mixins.py", line 241, in list
obj = self.gitlab.http_list(path, **data)
File "C:\Users\foo\AppData\Local\Programs\Python\Python38\lib\site-packages\gitlab\client.py", line 821, in http_list
return list(GitlabList(self, url, query_data, **kwargs))
File "C:\Users\foo\AppData\Local\Programs\Python\Python38\lib\site-packages\gitlab\client.py", line 1076, in __next__
return self.next()
File "C:\Users\foo\AppData\Local\Programs\Python\Python38\lib\site-packages\gitlab\client.py", line 1087, in next
self._query(self._next_url, **self._kwargs)
File "C:\Users\foo\AppData\Local\Programs\Python\Python38\lib\site-packages\gitlab\client.py", line 994, in _query
result = self._gl.http_request("get", url, query_data=query_data, **kwargs)
File "C:\Users\foo\AppData\Local\Programs\Python\Python38\lib\site-packages\gitlab\client.py", line 680, in http_request
result = self.session.request(
File "C:\Users\foo\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py", line 529, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\foo\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py", line 645, in send
r = adapter.send(request, **kwargs)
File "C:\Users\foo\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\adapters.py", line 519, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='foo.bar', port=443): Max retries exceeded with url:
/api/v4/projects?membership=false&order_by=created_at&owned=false&page=2&per_page=20&simple=false&sort=desc&starred=false&statistics=false&with_custom_attributes=false&with_issues_enabled=false&with_merge_requests_enabled=false
(Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000002033C9897C0>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))
Specifications
- OS: Windows 10 21H1
- python version: 3.8.10
- python-gitlab version: 3.3.0
- API version you are using (v3/v4): v4
- Gitlab server version (or gitlab.com): GitLab Community Edition 14.9.2
Activity
max-wittig commentedon Apr 20, 2022
Hi @pff729. I'm not sure. Hope I'm not confused here, but you're URL points to port 443. HTTPS always means 443, if not otherwise specified.
E.g. to change the port to 7443 in your case.
This is nothing special about python-gitlab. It's how to generally connect with web-services on other ports.
Does that help?
max-wittig commentedon Apr 20, 2022
There is a section called
Syntax. Might help you. https://en.wikipedia.org/wiki/Uniform_Resource_Identifierpff729 commentedon Apr 20, 2022
Sorry, I forgot to mention that: I added the port to the end of the URL, but the error log is the same, it still tries on 443.
max-wittig commentedon Apr 20, 2022
@pff729 Ahh okay. That changes the question. Could you please provide more example code? Also in our tests, we use port 8080, I think so that should actually work.
nejch commentedon Apr 20, 2022
In that case it looks like a misconfigured GitLab external URL to me. It happens on list with
&page=2. When usinglist()with paginated responses, the client will follow the link provided by the server for subsequent requests so if it's not 7443, it'll be incorrect.If you do
gl.enable_debug()and the port between the first and second request changes, you can confirm that it is a server configuration error. See also #1934 for a very similar issue where this was discussed.pff729 commentedon Apr 20, 2022
I added the
gl.enable_debug(), the first line of the debug isDEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): foo.bar:443So this port is already set for the first request and somehow I should modify it.
Also tried from Postman to send a GET request to
foo.bar:7443/api/v4/projectsand got back a 200 and the full list of projects.pff729 commentedon Apr 20, 2022
Also added the port to the end of the url, like
foo.bar:7443, this way the first query is successful with the correct port, but the second one uses the 443 port again.nejch commentedon Apr 20, 2022
Yes, as Max said above, you really need to set the
:7443port in the URL - that's the only way python-gitlab understands non-default ports, there is noportargument.This also likely confirms it is a server issue. I assume Postman works because it did not paginate the response, it just received the first page - so if you have over 20 projects you will not see all of them?
You likely missed this
external_urlconfig when customizing your port:https://docs.gitlab.com/omnibus/settings/nginx.html#change-the-default-port-and-the-ssl-certificate-locations
nejch commentedon Jun 24, 2022
@pff729 we would really need more info to proceed here, so I'll close this for now. I still think your server would need fixing in config, and we are tracking adding an explicit warning when python-gitlab detects a wrong server URL configuration in this issue #1977.