python - HTML 和 Flask POST 图像上传停止工作
问题描述
我的烧瓶/html POST 图像上传系统过去一直有效,但现在我看到图像没有上传到它应该上传到的文件夹。我在运行服务器时收到的错误消息是针对图像的压缩并显示“Nonetype has no attribute shape”,这是由于我认为是图像无法上传造成的。正如我在标题中所说,这段代码过去一直有效,有时当代码没有刷新服务器时会修复错误。HTML 代码:
<html>
<head>
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='style.css') }}">
<title>Upload</title>
</head>
<body>
<form method=POST id="submitbox" enctype=multipart/form-data action="{{ url_for('upload') }}">
<input type=file name=photo>
<input type="submit" id="submittext">
</form>
</body>
</html>
蟒蛇代码:
if request.method == 'POST' and 'photo' in request.files:
global file_name
file_name = photos.save(request.files['photo'])
print(file_name)
global file_path
file_path = os.path.join(r'FILEPATH', file_name)
print(file_path)
img = cv2.imread(file_path)
height, width, _ = img.shape
roi = img[0: height, 0: width]
_, compressedimage = cv2.imencode(".jpg", roi, [1, 90]
提前感谢您的帮助!
第 304 行,在上传高度、宽度、_ = img.shape AttributeError: 'NoneType' object has no attribute 'shape'
解决方案
推荐阅读
- python - 如何在 Python 2 中正确编写多处理代码
- javascript - 检测 IE < 11 是否可靠
- python - Python通过另一个进程发送命令,等待进程终止,然后重新启动系统?
- c - 为什么不 ++i || ++j && ++k 给出期望值
- postman - 是否可以从 Postman 应用程序中 JSON 数据文件中提到的路径上传图像
- python - 如何找到 numpy 矩阵的最小值?(在这种特殊情况下)
- protractor - 测试应该为每个规范登录
- c# - 具有不同列名的 SQL 批量复制映射?
- c# - 单实例 winforms 应用程序应存储当前用户详细信息,并在尝试打开时将其显示在另一个实例中
- r - 如何将 odbc 包安装到 Databricks 集群?