2bon2b
2bon2b

Reputation: 165

Why is functions-framework returning a 400 status code when i send it a file?

I am developing a micro services architecture locally on my laptop, where a flask app communicates with a Google cloud function (using functions-framework library).

In it,the following happens:

When the file is sent though the cloud function is returning a 400 status code (bad request).

What am I doing wrong?

===form.html===

<html>
   <body>
   <h1>Report</h1>

      <form action = "http://localhost:3000**/process**" method = "post" enctype = "multipart/form-data">
     <input type = "file" name = "file" />
    <input type = "hidden" name = "report" />
         <p><input type = "submit" value = "submit" /></p>
      </form>   
   </body>
</html>

===Flask===

...

@app.route('/process',methods = ['POST'])
def process():
      f = request.files['file']
      files = {'document': f.read()}
      headers = {'Content-type': 'multipart/form-data'}
      url='http://127.0.0.1:8080'
      r = requests.post(url,files=files,headers=headers)
      if r:
         return redirect(url_for('success',tool=r.text))

@app.route('/form')
def form():
   return render_template('form.html')


if __name__ == '__main__':
    app.run(port=3000)

===functions-framework===

def func2(request):
    file=request.files['document']
    return str(type(file))

Upvotes: 0

Views: 1438

Answers (1)

Rogelio Monter
Rogelio Monter

Reputation: 1216

In the documentation for Functions Framework, there are more links to learn more about this, particularly on how to use the Functions Framework for Python runtime. Here you can find a quickstart about error handling.

In this answer from another question, you could check how to implement an error handler for a given code error and get the description of the error in order to debug your code and know why you're getting the 400 status code error.

Upvotes: 1

Related Questions