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

SSL certificate projects list , 400 Bad Request · Issue #1934 · python-gitlab/python-gitlab · GitHub

Repository navigation

SSL certificate projects list , 400 Bad Request  #1934

Description

Description of the problem, including code/CLI snippet

I need to request it locally with an SSL certificate,The following code

import gitlab
import requests
from requests_pkcs12 import Pkcs12Adapter

BASE_URL = "https://gitlab.co-xx.com"
session = requests.Session()
session.mount(BASE_URL, Pkcs12Adapter(pkcs12_filename='cert/client-20220301.p12', pkcs12_password='test'))
gl = gitlab.Gitlab(url=BASE_URL, private_token="8J9HsANQo8zFsUZEwShK", api_version=4, session=session)

if __name__ == '__main__':
    groups_list = gl.groups.list()
    for group in groups_list:
        print('组名:{} [{}]'.format(group.name, group.id))
        g_projects = group.projects.list(all=True)

        for g_project in g_projects:
            print(g_project)

Expected Behavior

Print the list of items correctly

raise error(e.error_message, e.response_code, e.response_body) from e
gitlab.exceptions.GitlabListError: 400: <html>
<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>
</body>
</html>

Actual Behavior

The group list prints correctly,However, an exception occurred in obtaining the projects list

Specifications

  • python-gitlab version: 3.7
  • API version you are using (v3/v4): v4
  • Gitlab server version (or gitlab.com): gitlab-10.0.4

Activity

  1. nejch commented on Mar 26, 2022

    Member

    This looks more like a misconfigured gitlab or nginx config to me. Is your external_url set to http? This would send the wrong next links in paginated lists.

    Either way, please set gl.enable_debug() and paste the urllib3 debug logs so we can take a look.

    Are you really using gitlab 10.0.4? And what is the python-gitlab version? 3.7 is the version of python, I assume.

  2. lrk1056 commented on Mar 29, 2022

    Author


    gl.projects.list() no problem
    gl.projects.list(all=True) error

    DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): gitlab.co-xxx.com:443
    send: b'GET /api/v4/groups HTTP/1.1\r\nHost: gitlab.co-xxx.com\r\nUser-Agent: python-gitlab/3.2.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nPRIVATE-TOKEN: 8J9HsANQo8zFsUZEwShK\r\nContent-type: application/json\r\n\r\n'
    reply: 'HTTP/1.1 200 OK\r\n'
    header: Date: Tue, 29 Mar 2022 02:08:18 GMT
    header: Content-Type: application/json
    header: Content-Length: 338
    header: Connection: keep-alive
    header: Cache-Control: max-age=0, private, must-revalidate
    header: Etag: W/"e538701d9ed2366034e15285676c56b2"
    header: Link: <http://gitlab.co-xxx.com:443/api/v4/groups?order_by=name&owned=false&page=1&per_page=20&sort=asc&statistics=false>; rel="first", <http://gitlab.co-xxx.com:443/api/v4/groups?order_by=name&owned=false&page=1&per_page=20&sort=asc&statistics=false>; rel="last"
    header: Vary: Origin
    header: X-Frame-Options: SAMEORIGIN
    header: X-Next-Page: 
    header: X-Page: 1
    header: X-Per-Page: 20
    header: X-Prev-Page: 
    header: X-Request-Id: 9aa1f4e0-2761-44a0-bbd2-33102e47fbbc
    header: X-Runtime: 0.028858
    header: X-Total: 1
    header: X-Total-Pages: 1
    header: Server: elb
    ---------------------------- 组名:magic [551]
    send: b'GET /api/v4/projects HTTP/1.1\r\nHost: gitlab.co-xxx.com\r\nUser-Agent: python-gitlab/3.2.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nPRIVATE-TOKEN: 8J9HsANQo8zFsUZEwShK\r\nContent-type: application/json\r\n\r\n'
    DEBUG:urllib3.connectionpool:https://gitlab.co-xxx.com:443 "GET /api/v4/groups HTTP/1.1" 200 338
    reply: 'HTTP/1.1 200 OK\r\n'
    header: Date: Tue, 29 Mar 2022 02:08:18 GMT
    header: Content-Type: application/json
    header: Content-Length: 45650
    header: Connection: keep-alive
    header: Cache-Control: max-age=0, private, must-revalidate
    header: Etag: W/"0f984c4739c217ab01fb89e2ee389891"
    header: Link: <http://gitlab.co-xxx.com:443/api/v4/projects?archived=false&membership=false&order_by=created_at&owned=false&page=2&per_page=20&simple=false&sort=desc&starred=false&statistics=false&with_issues_enabled=false&with_merge_requests_enabled=false>; rel="next", <http://gitlab.co-xxx.com:443/api/v4/projects?archived=false&membership=false&order_by=created_at&owned=false&page=1&per_page=20&simple=false&sort=desc&starred=false&statistics=false&with_issues_enabled=false&with_merge_requests_enabled=false>; rel="first", <http://gitlab.co-xxx.com:443/api/v4/projects?archived=false&membership=false&order_by=created_at&owned=false&page=98&per_page=20&simple=false&sort=desc&starred=false&statistics=false&with_issues_enabled=false&with_merge_requests_enabled=false>; rel="last"
    header: Vary: Origin
    header: X-Frame-Options: SAMEORIGIN
    header: X-Next-Page: 2
    header: X-Page: 1
    header: X-Per-Page: 20
    header: X-Prev-Page: 
    header: X-Request-Id: 30bb567f-ff4e-4613-a9c8-92381ef74584
    header: X-Runtime: 0.501010
    header: X-Total: 1960
    header: X-Total-Pages: 98
    header: Server: elb
    DEBUG:urllib3.connectionpool:https://gitlab.co-xxx.com:443 "GET /api/v4/projects HTTP/1.1" 200 45650
    DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): gitlab.co-xxx.com:443
    send: b'GET /api/v4/projects?archived=false&membership=false&order_by=created_at&owned=false&page=2&per_page=20&simple=false&sort=desc&starred=false&statistics=false&with_issues_enabled=false&with_merge_requests_enabled=false HTTP/1.1\r\nHost: gitlab.co-xxx.com:443\r\nUser-Agent: python-gitlab/3.2.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nPRIVATE-TOKEN: 8J9HsANQo8zFsUZEwShK\r\nContent-type: application/json\r\n\r\n'
    DEBUG:urllib3.connectionpool:http://gitlab.co-xxx.com:443 "GET /api/v4/projects?archived=false&membership=false&order_by=created_at&owned=false&page=2&per_page=20&simple=false&sort=desc&starred=false&statistics=false&with_issues_enabled=false&with_merge_requests_enabled=false HTTP/1.1" 400 236
    Traceback (most recent call last):
      File "/Users/liurenkui/workSpace/Python/Mario/venv/lib/python3.7/site-packages/gitlab/exceptions.py", line 311, in wrapped_f
        return f(*args, **kwargs)
      File "/Users/liurenkui/workSpace/Python/Mario/venv/lib/python3.7/site-packages/gitlab/mixins.py", line 241, in list
        obj = self.gitlab.http_list(path, **data)
      File "/Users/liurenkui/workSpace/Python/Mario/venv/lib/python3.7/site-packages/gitlab/client.py", line 817, in http_list
        return list(GitlabList(self, url, query_data, **kwargs))
      File "/Users/liurenkui/workSpace/Python/Mario/venv/lib/python3.7/site-packages/gitlab/client.py", line 1072, in __next__
        return self.next()
      File "/Users/liurenkui/workSpace/Python/Mario/venv/lib/python3.7/site-packages/gitlab/client.py", line 1083, in next
        self._query(self._next_url, **self._kwargs)
      File "/Users/liurenkui/workSpace/Python/Mario/venv/lib/python3.7/site-packages/gitlab/client.py", line 990, in _query
        result = self._gl.http_request("get", url, query_data=query_data, **kwargs)
      File "/Users/liurenkui/workSpace/Python/Mario/venv/lib/python3.7/site-packages/gitlab/client.py", line 730, in http_request
        response_body=result.content,
    gitlab.exceptions.GitlabHttpError: 400: <html>
    <head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
    <body bgcolor="white">
    <center><h1>400 Bad Request</h1></center>
    <center>The plain HTTP request was sent to HTTPS port</center>
    </body>
    </html>
    
    
    The above exception was the direct cause of the following exception:
    
    Traceback (most recent call last):
      File "/Users/liurenkui/workSpace/Python/Mario/gitlab-xxl/Analysis_Data.py", line 27, in <module>
        for g_project in gl.projects.list(all=True):
      File "/Users/liurenkui/workSpace/Python/Mario/venv/lib/python3.7/site-packages/gitlab/exceptions.py", line 313, in wrapped_f
        raise error(e.error_message, e.response_code, e.response_body) from e
    gitlab.exceptions.GitlabListError: 400: <html>
    <head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
    <body bgcolor="white">
    <center><h1>400 Bad Request</h1></center>
    <center>The plain HTTP request was sent to HTTPS port</center>
    </body>
    </html>
    
    reply: 'HTTP/1.1 400 Bad Request\r\n'
    header: Date: Tue, 29 Mar 2022 02:08:18 GMT
    header: Content-Type: text/html
    header: Content-Length: 236
    header: Connection: close
    header: Server: elb
    
    

    python-version: 3.7
    Gitlab server version: gitlab-10.0.4

  3. nejch commented on Mar 31, 2022

    Member

    I think my suspicion was correct and your gitlab is configured to advertise an HTTP url instead of HTTPS. This sends the wrong link to follow when using list(all=True) and making subsequent requests (all links in header: Link: are http). See:

    DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): gitlab.co-xxx.com:443
    ...
    DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): gitlab.co-xxx.com:443
    

    Tell your administrator to configure the external URL properly: you should use HTTPS, not HTTP:
    https://docs.gitlab.com/omnibus/settings/configuration.html#configure-the-external-url-for-gitlab

    I'm going to close this as it's an issue with your GitLab instance and not python-gitlab but please reopen if you still have issues after you've fixed the external_url. Note gitlab 10.x is really old and we can't really support that. I suggest you gradually upgrade to 14.9.

    @X-rapido please also revoke your private token and create a new one as it was exposed in this log (next time take care to redact these before pasting the logs)

  4. lrk1056 commented on Mar 31, 2022

    Author

    Thank you for your remind, Thank you for reply

  5. locked as resolved and limited conversation to collaborators on Apr 3, 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

    Labels

    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