2017-02-17 2 views
0

Ich versuche, eine Datei in eine Flask-App hochladen und es als Pandas DataFrame verwenden, nicht speichern. Ich habe eine Flasche App mit dem folgenden Endpunkt: `` `Hochladen von Datei in Flask App mit Curl funktioniert nicht

@app.route('/upload_file/', methods=['POST']) 
def upload_file(): 

     afile = request.files['file'] 
     ff = file.read(afile) 
     print ff 

     return str(ff) 
``` 
I am trying to use curl to use POST to upload the file using: 

```curl -v -F file='/Users/asharma/../cpr_all_platforms.csv' http://127.0.0.1:5000/upload_file/``` 

ich die folgende Fehlermeldung erhalten:

``` 
* Trying 127.0.0.1... 
* Connected to 127.0.0.1 (127.0.0.1) port 5000 (#0) 
> POST /upload_file/ HTTP/1.1 
> Host: 127.0.0.1:5000 
> User-Agent: curl/7.49.0 
> Accept: */* 
> Content-Length: 207 
> Expect: 100-continue 
> Content-Type: multipart/form-data; boundary=------------------------b313bf20e62c9f7c 
> 
< HTTP/1.1 100 Continue 
* HTTP 1.0, assume close after body 
< HTTP/1.0 400 BAD REQUEST 
< Content-Type: text/html 
< Content-Length: 192 
< Server: Werkzeug/0.11.11 Python/2.7.12 
< Date: Fri, 17 Feb 2017 19:00:37 GMT 
< 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> 
<title>400 Bad Request</title> 
<h1>Bad Request</h1> 
<p>The browser (or proxy) sent a request that this server could not understand.</p> 
* Closing connection 0 

` ``

Antwort

0
@app.route('/upload_file/', methods=['POST']) 
def upload_file(): 

     file = request.files['file'] 

     ff = pd.read_csv(file) 

     return str(ff) 

Der Endpunkt wird Hit mit locken und der Dateiname:

curl -i -X POST -F [email protected]/Users/asharma/../cpr_all_platforms.csv http://127.0.0.1:5000/upload_file/ 
Verwandte Themen