FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Can't change port from 443 · Issue #1977 · python-gitlab/python-gitlab · GitHub

Repository navigation

Can't change port from 443 #1977

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

  1. max-wittig commented on Apr 20, 2022

    Member

    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.

    GITLAB_URL = 'https://foo.bar:7443'
    

    This is nothing special about python-gitlab. It's how to generally connect with web-services on other ports.

    Does that help?

  2. max-wittig commented on Apr 20, 2022

    Member

    There is a section called Syntax. Might help you. https://en.wikipedia.org/wiki/Uniform_Resource_Identifier

  3. pff729 commented on Apr 20, 2022

    Author

    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.

  4. max-wittig commented on Apr 20, 2022

    Member

    @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.

  5. nejch commented on Apr 20, 2022

    Member

    In that case it looks like a misconfigured GitLab external URL to me. It happens on list with &page=2. When using list() 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.

  6. pff729 commented on Apr 20, 2022

    Author

    I added the gl.enable_debug(), the first line of the debug is
    DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): foo.bar:443
    So 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/projects and got back a 200 and the full list of projects.

  7. pff729 commented on Apr 20, 2022

    Author

    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.

  8. nejch commented on Apr 20, 2022

    Member

    Also added the port to the end of the url, like foo.bar:7443

    Yes, as Max said above, you really need to set the :7443 port in the URL - that's the only way python-gitlab understands non-default ports, there is no port argument.

    this way the first query is successful with the correct port, but the second one uses the 443 port again.

    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_url config when customizing your port:
    https://docs.gitlab.com/omnibus/settings/nginx.html#change-the-default-port-and-the-ssl-certificate-locations

  9. nejch commented on Jun 24, 2022

    Member

    @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.

  10. locked as resolved and limited conversation to collaborators on Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL