I am sending a avro file as binary data to a flask application. The flask application is running in a container with python 3.6.
When I use the image in my local environment is working fine. I am getting the proper response. But when I deploy the image to kubernates, for some weird reason I am not able to decode the avro payload. Not sure what is related to the encode or the SO running the container.
For send the data I am using the following curl command:
curl --location --request POST 'https://foo/endpoint' \
--header 'Content-Type: application/avro;charset=UTF-8' \
--header 'Accept: application/avro+json' \
--data-binary '#c:/blabla/file.avro'
In my flask application I am receiving the request as:
#application.route('/endpoint', methods=['POST'])
def get_attributes_response(foo):
res= request.get_data()
Thanks!!!
Related
We currently have a cURL request like below and we'd like to convert it into Python. How do I do this? From my googling, all I am seeing is how to send files but not a folder files. Thank you!
curl
--location
--request PUT 'https://some-url.com/files' \
--header 'Content-Type: application/octet-stream' \
--data-binary '#/path/to/files'
I have to upload an artifact to JFrog Artifactory using the cUrl request
sample:
curl -sSf -H "X-JFrog-Art-Api:<API_KEY>" \
-X PUT \
-T file.zip \
'http(s)://<ARTIFACTORY_URL>/<REPO>/<PATH>/file.zip;released=true;build.number=1.0'
Now, I am using urllib2 (cannot use higher libraries like requests) and I understand the Header parts and data part , but the flags/options like -T -sSf, how to feed these in urllib?
I have similar apps on Flask and FastAPI.
When I do this curl requests with Flask, that is all right:
Without TLS:
curl -X POST -H "Content-Type: application/json" -d '{"method": "account.auth"}' http://X.X.X.X:5050/
{"error":0,"result":{"token":"XXX"}}
With TLS:
curl -X POST -H "Content-Type: application/json" -d '{"method": "account.auth"}' https://example.com:8443/api/
{"error":0,"result":{"token":"XXX"}}
!!! But with FastAPI I get another result:
Without TLS:
curl -X POST -H "Content-Type: application/json" -d '{"method": "account.auth"}' http://X.X.X.X:5050/
{"error":0,"result":{"token":"XXX"}}
With TLS:
curl -X POST -H "Content-Type: application/json" -d '{"method": "account.auth"}' https://example.com:8443/api/
Unsupported upgrade request.
How to fix problem with "Unsupported upgrade request."? And what is it? Flask are working with it normally.
This same issue usually seems to arise from incomplete uvicorn installations, but is usually related to websockets.
A solution for this issue might be to reinstall uvicorn with the recommended (by FastAPI) extras:
python3 -m pip uninstall uvicorn
python3 -m pip install uvicorn[standard]
I had this problem using java to access the api. The solution was to set HTTP Request to 1.1
var httpRequest = HttpRequest.newBuilder()
.uri(URI.create("http://127.0.0.1:8000/jobs"))
.version(HttpClient.Version.HTTP_1_1)
.GET()
.build();
I'm working on a Python 3.6 project in which I need to create a repository on the docker hub account by using API. I have googled a lot but couldn't find any API client to create repositories on docker hub account.
I have found only this module dockercloud from here and tried it in this way:
dockercloud.user = 'arycloud'
dockercloud.apikey = 'API_KEY'
print(client.Repository.list())
But it returns an error like this:
dockercloud.api.exceptions.AuthError: error getting credentials - err: exec: "docker-credential-osxkeychain": executable file not found in $PATH, out: ``
Is there any way to create a repo on Docker Hub using API?
The API documentation does not describe any mechanism for creating repositories on any registry, Docker Hub included.
However, I was able to create a repository using curl to send a POST request:
TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d '{"username": "'${UNAME}'", "password": "'${UPASS}'"}' https://hub.docker.com/v2/users/login/ | jq -r .token)
curl -s -H "Authorization: JWT ${TOKEN}" "https://hub.docker.com/v2/repositories/" \
--data 'description=test' \
--data 'full_description=full-description' \
--data 'is_private=false' \
--data 'name=test' \
--data "namespace=${UNAME}"
I am trying to convert the below code in curl to python2 urllib2 request call for performing a "PUT" operation, it works fine with cURL but i am clueless on getting this converted to python2 code.
cURL
curl -X PUT -u myUser:myPassword -T test.txt “http://localhost:8081/artifactory/libs-release-local/test/test.txt”
The problem i face is with the "-T" flag i am not sure how set this in urllib2 call. I tried using Postman for help by adding file to Body->form-data->file
But the code is converted as below which i suspect is not the transfer file call.
curl -X PUT \
http://localhost:8081/artifactory/my-repository/my/new/artifact/directory/file.txt \
-H 'Cache-Control: no-cache' \
-H 'Postman-Token: 4ffbfca4-a4be-09de-c8ab-0731a2d67009' \
-H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
-F '=#C:\Devops\file.txt'
I tried looking at documentations specified here under -T/--upload-file it does not help. Any suggestions.
https://www.computerhope.com/unix/curl.html
https://curl.haxx.se/libcurl/c/options-in-examples.html