Code:
In [31]: response = requests.post(
...: gql_endpoint,
...: headers = gql_headers,
...: auth=HTTPBasicAuth(gql_user, gql_pass),
...: data=gql_query,
...: verify='/etc/ssl/certs/COMPANYrootca2022ec.pem'
...: )
...: ## DEBUG
...: #print('###### DEBUG requests response OUTPUT')
...: return response.text
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In [31], line 1
----> 1 response = requests.post(
2 gql_endpoint,
3 headers = gql_headers,
4 auth=HTTPBasicAuth(gql_user, gql_pass),
5 data=gql_query,
6 verify='/etc/ssl/certs/COMPANYrootca2022ec.pem'
7 )
8 ## DEBUG
9 #print('###### DEBUG requests response OUTPUT')
10 return response.text
File /usr/lib/python3/dist-packages/requests/api.py:115, in post(url, data, json, **kwargs)
103 def post(url, data=None, json=None, **kwargs):
104 r"""Sends a POST request.
105
106 :param url: URL for the new :class:`Request` object.
(...)
112 :rtype: requests.Response
113 """
--> 115 return request("post", url, data=data, json=json, **kwargs)
File /usr/lib/python3/dist-packages/requests/api.py:59, in request(method, url, **kwargs)
55 # By using the 'with' statement we are sure the session is closed, thus we
56 # avoid leaving sockets open which can trigger a ResourceWarning in some
57 # cases, and look like a memory leak in others.
58 with sessions.Session() as session:
---> 59 return session.request(method=method, url=url, **kwargs)
File /usr/lib/python3/dist-packages/requests/sessions.py:573, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
560 # Create the Request.
561 req = Request(
562 method=method.upper(),
563 url=url,
(...)
571 hooks=hooks,
572 )
--> 573 prep = self.prepare_request(req)
575 proxies = proxies or {}
577 settings = self.merge_environment_settings(
578 prep.url, proxies, stream, verify, cert
579 )
File /usr/lib/python3/dist-packages/requests/sessions.py:484, in Session.prepare_request(self, request)
481 auth = get_netrc_auth(request.url)
483 p = PreparedRequest()
--> 484 p.prepare(
485 method=request.method.upper(),
486 url=request.url,
487 files=request.files,
488 data=request.data,
489 json=request.json,
490 headers=merge_setting(
491 request.headers, self.headers, dict_class=CaseInsensitiveDict
492 ),
493 params=merge_setting(request.params, self.params),
494 auth=merge_setting(auth, self.auth),
495 cookies=merged_cookies,
496 hooks=merge_hooks(request.hooks, self.hooks),
497 )
498 return p
File /usr/lib/python3/dist-packages/requests/models.py:369, in PreparedRequest.prepare(self, method, url, headers, files, data, params, auth, cookies, hooks, json)
367 self.prepare_method(method)
368 self.prepare_url(url, params)
--> 369 self.prepare_headers(headers)
370 self.prepare_cookies(cookies)
371 self.prepare_body(data, files, json)
File /usr/lib/python3/dist-packages/requests/models.py:489, in PreparedRequest.prepare_headers(self, headers)
487 self.headers = CaseInsensitiveDict()
488 if headers:
--> 489 for header in headers.items():
490 # Raise exception on invalid header value.
491 check_header_validity(header)
492 name, value = header
AttributeError: 'str' object has no attribute 'items'
Functionsaufruf
Code:
def __get_graphql_data__(gql_endpoint, gql_mode, gql_query, gql_headers):
## GraphQL Tooluser Credentials
parser = configparser.ConfigParser()
parser.read(credentials_path)
gql_user = parser.get('GRAPHQL', 'gql_user')
gql_pass = parser.get('GRAPHQL', 'gql_pass')
try:
response = requests.post(
gql_endpoint,
headers = str(gql_headers),
auth=HTTPBasicAuth(gql_user, gql_pass),
data=gql_query,
verify='/etc/ssl/certs/COMPANYrootca2022ec.pem'
)
## DEBUG
#print('###### DEBUG requests response OUTPUT')
return response.text
except OSError:
print('Ein Problem HTTP ' + response + ' mit ' + gql_endpoint)
Lesezeichen