flask
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"metadata": {},
|
||||
"cell_type": "markdown",
|
||||
"source": "### 发送文件",
|
||||
"id": "259126b0b53fdd9f"
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"id": "initial_id",
|
||||
"metadata": {
|
||||
"collapsed": true,
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-09-02T09:10:07.287763Z",
|
||||
"start_time": "2025-09-02T09:10:07.276787Z"
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"import requests\n",
|
||||
"\n",
|
||||
"url = 'http://127.0.0.1:5000/upload' # 你的 Flask 服务地址\n",
|
||||
"file_path = 'D:\\Idea Project\\python\\demo.py' # 要上传的文件路径\n",
|
||||
"\n",
|
||||
"with open(file_path, 'rb') as f:\n",
|
||||
" files = {'file': f}\n",
|
||||
" response = requests.post(url, files=files)\n",
|
||||
"\n",
|
||||
"print(response.text)"
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"File uploaded successfully: demo.py\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"<>:4: SyntaxWarning: invalid escape sequence '\\I'\n",
|
||||
"<>:4: SyntaxWarning: invalid escape sequence '\\I'\n",
|
||||
"C:\\Users\\zy187\\AppData\\Local\\Temp\\ipykernel_3844\\645906349.py:4: SyntaxWarning: invalid escape sequence '\\I'\n",
|
||||
" file_path = 'D:\\Idea Project\\python\\demo.py' # 要上传的文件路径\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"execution_count": 5
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 2
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython2",
|
||||
"version": "2.7.6"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
Reference in New Issue
Block a user