Python request上传图片到云服务器

在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
Python request上传图片到云服务器

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

以上是 Python request上传图片到云服务器 的全部内容, 来源链接: utcz.com/a/162342.html

回到顶部