4

I am trying to send a file to a function on picloud via REST with poster python library on google app engine (An HTML JPEG image upload). But the function throws this error :

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

I have set the function's output encoding to raw, also I've followed the docs to detail.

Here are some of the function details.

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

Here is a relevant 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,in order to include the real function arguments

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

I get the error

{"error": {"msg": " charset is defined multiple times", "code": 445, "retry": false}}

I have also tried wrapping the parameters in a dictionary, rather than separate MultipartParam instances

Please help.

Mike Müller
  • 82,630
  • 20
  • 166
  • 161
Blessing
  • 71
  • 4

1 Answers1

1

You got a space in your argument:

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

This should likely be:

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

Note that some_file_uploaded_via_html_form is one word.

Mike Müller
  • 82,630
  • 20
  • 166
  • 161
  • Thanks! I have adjusted that,but the problem still remains – Blessing May 26 '13 at 13:29
  • There is a missing _)_ here _value=filename_variable)_ and here _value=some_file_uploaded_via_html_form)_. Check how it looks like in your actual code. – Mike Müller May 26 '13 at 16:30
  • Here (Yes),but it is normal in the original code.otherwise it wouldn't run at all: it'll give a syntax error.I feel the code might be semantically wrong,or the its screwing up somewhere but I can't just figure out the problem.I've already posted the part of it that does the real work ,other parts are just if -else statements,html form and library definitions. – Blessing May 26 '13 at 17:50