Python request上传图片到云服务器

发布于 2022-09-12 01:16:41 字数 2075 浏览 24 评论 0

在pycharm上用python request上传图片到指定url中

相关代码

// 请把代码文本粘贴到下方(请勿用图片代替代码)

# -*- coding:utf-8 -*-  
import requests  
import os  
import re  
url = r'http://**.**.**.***:8080/static/siitep/img'  
#url = r'http://**.**.**.***:8080'    
i = 1  
for path, dirpath, file in os.walk(r"C:\\Users\\xiaomi\\Desktop\\jietu"):  
    for f in file:  
        r1 = r'(png)'  
        if re.findall(r1, f):  
            files = {'img': (f, open('C:/Users/xiaomi/Desktop/jietu/'+f, 'rb'), 'png', {})}  
            print(files)  
            res = requests.request("POST", url, data={"type": "1"}, files=files)  
            i += 1  
print(res.text)

出现的错误:404

<!doctype html><html lang="en"><head><title>HTTP Status 404 – Not Found</title><style type="text/css">H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}</style></head><body><h1>HTTP Status 404 – Not Found</h1>


<p>Type Status Report</p><p>Message /static/siitep/img/</p><p>Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.</p>
<h3>Apache Tomcat/7.0.92</h3></body></html>

问题出现的平台版本及自己尝试过哪些方法

在浏览器打开这个url也是404
image.png

感觉我这个代码是把图片传到了一个网页上的样子,但是我是想在本地用Python把照片传到服务器的一个文件夹里,请问这样的话我这里的代码要怎么改呢?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文