Published picloud function throws error

I am trying to send a file to a function on picloud via REST with a paid python library in the Google App Engine (uploading an HTML JPEG image). But the function raises this error:

{"error": {"msg": "Function arguments (POST data) are not valid JSON", "code": 446, "data": "{'parameter': u 'filename'}", "retry": false} }

I set the encoding of the output of the function to raw , I also followed the documents to the details.

Here are some of the details of the function.

Function name: detector(name,ifile) takes two arguments, the image file and its name

Here is the important part of the code:

 #all needed classes and libraries have been imported,urlfetch, poster,MultipartParam class ect. #here we go! params=[] params.append(MultipartParam("Imagename",filename="anyname.jpg",filetype="application/octet-stream",value=some_file_uploaded_via_html_form)) #http_headers has been defined with appropriate autorization credentials datagen,headers=multipart.encode(params) data=str().join(datagen) result=urlfetch.fetch(url=my_defined_function_url,payload=data,method=urlfetch.POST,headers=http_headers) print result.content 

When I add the following lines to include the arguments of the real function

 params.append(MultipartParam('name',value=filename_variable) params.append(MultipartParam('ifile',value=some_file_uploaded_via_html_form) 

I get an error

{"error": {"msg": "charset is determined several times", "code": 445, "retry": false}}

I also tried to wrap the parameters in the dictionary, not individual MultipartParam instances

Please, help.

+4
source share
1 answer

You have a space in your argument:

 params.append(MultipartParam('ifile',value=some_file_uploaded_via_html _form) 

It should be:

 params.append(MultipartParam('ifile',value=some_file_uploaded_via_html_form) 

Please note that some_file_uploaded_via_html_form is one word.

+1
source

Source: https://habr.com/ru/post/1482819/