MCPcopy Create free account
hub / github.com/bundesAPI/smard-api / request

Method request

python-client/deutschland/smard/rest.py:108–259  ·  view source on GitHub ↗

Perform requests. :param method: http request method :param url: http request url :param query_params: query parameters in the url :param headers: http request headers :param body: request json body, for `application/json` :param post_params: request

(
        self,
        method,
        url,
        query_params=None,
        headers=None,
        body=None,
        post_params=None,
        _preload_content=True,
        _request_timeout=None,
    )

Source from the content-addressed store, hash-verified

106 )
107
108 def request(
109 self,
110 method,
111 url,
112 query_params=None,
113 headers=None,
114 body=None,
115 post_params=None,
116 _preload_content=True,
117 _request_timeout=None,
118 ):
119 """Perform requests.
120
121 :param method: http request method
122 :param url: http request url
123 :param query_params: query parameters in the url
124 :param headers: http request headers
125 :param body: request json body, for `application/json`
126 :param post_params: request post parameters,
127 `application/x-www-form-urlencoded`
128 and `multipart/form-data`
129 :param _preload_content: if False, the urllib3.HTTPResponse object will
130 be returned without reading/decoding response
131 data. Default is True.
132 :param _request_timeout: timeout setting for this request. If one
133 number provided, it will be total request
134 timeout. It can also be a pair (tuple) of
135 (connection, read) timeouts.
136 """
137 method = method.upper()
138 assert method in ["GET", "HEAD", "DELETE", "POST", "PUT", "PATCH", "OPTIONS"]
139
140 if post_params and body:
141 raise ApiValueError(
142 "body parameter cannot be used with post_params parameter."
143 )
144
145 post_params = post_params or {}
146 headers = headers or {}
147
148 timeout = None
149 if _request_timeout:
150 if isinstance(_request_timeout, (int, float)): # noqa: E501,F821
151 timeout = urllib3.Timeout(total=_request_timeout)
152 elif isinstance(_request_timeout, tuple) and len(_request_timeout) == 2:
153 timeout = urllib3.Timeout(
154 connect=_request_timeout[0], read=_request_timeout[1]
155 )
156
157 try:
158 # For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
159 if method in ["POST", "PUT", "PATCH", "OPTIONS", "DELETE"]:
160 # Only set a default Content-Type for POST, PUT, PATCH and OPTIONS requests
161 if (method != "DELETE") and ("Content-Type" not in headers):
162 headers["Content-Type"] = "application/json"
163 if query_params:
164 url += "?" + urlencode(query_params)
165 if ("Content-Type" not in headers) or (

Callers 7

GETMethod · 0.95
HEADMethod · 0.95
OPTIONSMethod · 0.95
DELETEMethod · 0.95
POSTMethod · 0.95
PUTMethod · 0.95
PATCHMethod · 0.95

Calls 8

ApiValueErrorClass · 0.90
ApiExceptionClass · 0.90
ForbiddenExceptionClass · 0.90
NotFoundExceptionClass · 0.90
ServiceExceptionClass · 0.90
RESTResponseClass · 0.85
debugMethod · 0.80

Tested by

no test coverage detected