How to authenticate for swagger_client?
I generated a client - swagger_client.
docker run --rm -v c:\!SAVE\client\:/local swaggerapi/swagger-codegen-cli generate -i https://nexus.dear.com.ru/service/rest/swagger.json -l python -o /local/out/python
I import it to my program and I’m trying to get a list of Components, but I always get 403 Forbidden.
This is the program itself.
from __future__ import print_function
import time
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
def main():
# create an instance of the API class
configuration = swagger_client.Configuration()
configuration.host = 'http://172.26.12.108:8081/service/rest'
configuration.username = 'myadmin'
configuration.password = 'strongpass'
#configuration.verify_ssl = False
configuration.debug = True
api_instance = swagger_client.ComponentsApi(swagger_client.ApiClient(configuration))
repository = 'pp-docker' # str
try:
result = api_instance.get_components(repository=repository)
print(result)
except ApiException as e:
print("Exception when calling ComponentsApi->get_components: %s\n" % e)
if __name__ == '__main__':
main()
With debugging enabled, I don’t see any authentication happening.
2022-09-01 11:16:46,358 DEBUG Starting new HTTP connection (1): 172.26.12.108:8081
send: b'GET /service/rest/v1/components?repository=minust-pp-docker HTTP/1.1\r\nHost: 172.26.12.108:8081\r\nAccept-Encoding: identity\r\nAccept: application/json\r\nContent-Type: application/json\r\nUser-Agent: Swagger-Codegen/1.0.0/python\r\n\r\n'
reply: 'HTTP/1.1 403 Forbidden\r\n'
header: Date: Thu, 01 Sep 2022 08:16:47 GMT
header: Server: Nexus/3.29.2-02 (OSS)
header: X-Content-Type-Options: nosniff
header: X-Siesta-FaultId: 1c212422-7f95-4d56-885b-667d7620cc75
header: Content-Length: 0
Exception when calling ComponentsApi->get_components: (403)
Reason: Forbidden
HTTP response headers: HTTPHeaderDict({'Date': 'Thu, 01 Sep 2022 08:16:47 GMT', 'Server': 'Nexus/3.29.2-02 (OSS)', 'X-Content-Type-Options': 'nosniff', 'X-Siesta-FaultId': '1c212422-7f95-4d56-885b-667d7620cc75', 'Content-Length': '0'})
2022-09-01 11:16:46,532 DEBUG http://172.26.12.108:8081 "GET /service/rest/v1/components?repository=minust-pp-docker HTTP/1.1" 403 0
2022-09-01 11:16:46,532 DEBUG response body: