精易论坛

标题: [python]利用米哈游服务器做直连网盘-python脚本-支持windows [打印本页]

作者: eyyhs    时间: 2024-10-6 13:06
标题: [python]利用米哈游服务器做直连网盘-python脚本-支持windows
本帖最后由 eyyhs 于 2024-10-6 13:07 编辑

接上个帖子
https://125.confly.eu.org/forum.php?mod ... rtype=1#pid29033712

有的人不会用php,并且部署服务器上传也有限制
这次写一份python的脚本,可以自己部署在本地满速上传下载方便使用!

windows本地成品例子:https://plat-sh-community-prod-upload-ugc.oss-cn-shanghai.aliyuncs.com/upload/2024/10/06/408757828/b53a68c55c243bc806adb2f005f67491_6017556270595386072.jpg?response-content-type=application%2Fzip%3B%20charset%3DUTF-8

测试视频文件(直接浏览器在线观看):
https://plat-sh-community-prod-upload-ugc.oss-cn-shanghai.aliyuncs.com/upload/2024/09/18/437001026/c2c88467d68be254cde987eb96222c0c_8789320676353527728.jpg

python脚本源码:

[Python] 纯文本查看 复制代码
import requests
import mimetypes


# 获取上传地址
def get_url():
    response = requests.get('https://video-oss.vercel.app/link')
    return response.text


def upload_file(file_path):
    url = get_url()
    # 打开文件
    with open(file_path, 'rb') as f:
        # 使用 PUT 方法上传文件
        requests.put(url, data=f, headers={
            'Content-Type': 'image/jpeg'
        })
        print(f'上传成功: {url}?response-content-type={mimetypes.guess_type(file_path)[0]}')


# 改成自己要上传的文件路径
upload_file('image.gif')



作者: JYYeah    时间: 2024-10-6 13:54
感谢分享!!!!
作者: cqcc    时间: 2024-10-6 14:02
本帖最后由 cqcc 于 2024-10-6 14:06 编辑
  
子程序名返回值类型公开备 注
获取上传地址  
变量名类 型静态数组备 注
网页访问对象文本型 
响应内容文本型 
网页访问对象 = https://video-oss.vercel.app/link
响应内容 = 到文本 (HTTP 读文件 (网页访问对象))
返回 (响应内容)
子程序名返回值类型公开备 注
上传文件逻辑型 
参数名类 型参考可空数组备 注
文件路径文本型
变量名类 型静态数组备 注
文件内容字节集 
上传地址文本型 
发送结果文本型 
文件内容 = 读入文件 (文件路径)
上传地址 = 获取上传地址 ()
发送结果 = HTTP 文件上传 (上传地址, “PUT”, 文件内容, “Content-Type: image/jpeg”)
调试输出 (“上传成功: ” + 上传地址 + “?response-content-type=”取文件类型 (文件路径))
返回 ()
窗口程序集名保 留  保 留备 注
窗口程序集1   
子程序名返回值类型公开备 注
_按钮1_被单击  
上传文件 (“image.gif”)


i支持库列表   支持库注释   
spec特殊功能支持库
internet互联网支持库
iconv编码转换支持库


作者: chuanqibuding    时间: 2024-10-6 14:15
本帖最后由 chuanqibuding 于 2024-10-6 14:37 编辑
cqcc 发表于 2024-10-6 14:02
[e=0].版本 2

.支持库 spec

用不了!
作者: 一指温柔    时间: 2024-10-6 17:16
感谢分享
作者: 亿万    时间: 2024-10-6 19:39
感谢分享
作者: pipicool    时间: 2024-10-6 20:32
学习一下
作者: Channge    时间: 2024-10-6 21:55
requests 这个不存在
作者: WENYEA    时间: 2024-10-7 00:18
在写份C++的呗大佬
作者: ctry78985    时间: 2024-10-7 08:08
感谢分享
作者: year1970    时间: 2024-10-7 08:40
感谢分享
作者: 吴磊磊    时间: 2024-10-7 09:37
有没有人用易语言写出来啊?
作者: 小虎来了    时间: 2024-10-7 09:58
感谢分享。
作者: Channge    时间: 2024-10-7 12:43
没用啊  运行一堆错误
作者: Channge    时间: 2024-10-7 14:06
他返回我这个 Traceback (most recent call last):   File "D:\_Python\Lib\site-packages\urllib3\connection.py", line 199, in _new_conn     sock = connection.create_connection(            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^   File "D:\_Python\Lib\site-packages\urllib3\util\connection.py", line 85, in create_connection     raise err   File "D:\_Python\Lib\site-packages\urllib3\util\connection.py", line 73, in create_connection     sock.connect(sa) TimeoutError: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。  The above exception was the direct cause of the following exception:  Traceback (most recent call last):   File "D:\_Python\Lib\site-packages\urllib3\connectionpool.py", line 789, in urlopen     response = self._make_request(                ^^^^^^^^^^^^^^^^^^^   File "D:\_Python\Lib\site-packages\urllib3\connectionpool.py", line 490, in _make_request     raise new_e   File "D:\_Python\Lib\site-packages\urllib3\connectionpool.py", line 466, in _make_request     self._validate_conn(conn)   File "D:\_Python\Lib\site-packages\urllib3\connectionpool.py", line 1095, in _validate_conn     conn.connect()   File "D:\_Python\Lib\site-packages\urllib3\connection.py", line 693, in connect     self.sock = sock = self._new_conn()                        ^^^^^^^^^^^^^^^^   File "D:\_Python\Lib\site-packages\urllib3\connection.py", line 208, in _new_conn     raise ConnectTimeoutError( urllib3.exceptions.ConnectTimeoutError: (<urllib3.connection.HTTPSConnection object at 0x000002669FF9B4D0>, 'Connection to video-oss.vercel.app timed out. (connect timeout=None)')  The above exception was the direct cause of the following exception:  Traceback (most recent call last):   File "D:\_Python\Lib\site-packages\requests\adapters.py", line 667, in send     resp = conn.urlopen(            ^^^^^^^^^^^^^   File "D:\_Python\Lib\site-packages\urllib3\connectionpool.py", line 843, in urlopen     retries = retries.increment(               ^^^^^^^^^^^^^^^^^^   File "D:\_Python\Lib\site-packages\urllib3\util\retry.py", line 519, in increment     raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='video-oss.vercel.app', port=443): Max retries exceeded with url: /link (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x000002669FF9B4D0>, 'Connection to video-oss.vercel.app timed out. (connect timeout=None)'))  During handling of the above exception, another exception occurred:  Traceback (most recent call last):   File "C:\Users\13173\Desktop\1pytho\yunli.py", line 23, in <module>     upload_file('yunli.txt')   File "C:\Users\13173\Desktop\1pytho\yunli.py", line 12, in upload_file     url = get_url()           ^^^^^^^^^   File "C:\Users\13173\Desktop\1pytho\yunli.py", line 7, in get_url     response = requests.get('https://video-oss.vercel.app/link')                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^   File "D:\_Python\Lib\site-packages\requests\api.py", line 73, in get     return request("get", url, params=params, **kwargs)            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^   File "D:\_Python\Lib\site-packages\requests\api.py", line 59, in request     return session.request(method=method, url=url, **kwargs)            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^   File "D:\_Python\Lib\site-packages\requests\sessions.py", line 589, in request     resp = self.send(prep, **send_kwargs)            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^   File "D:\_Python\Lib\site-packages\requests\sessions.py", line 703, in send     r = adapter.send(request, **kwargs)         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^   File "D:\_Python\Lib\site-packages\requests\adapters.py", line 688, in send     raise ConnectTimeout(e, request=request) requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='video-oss.vercel.app', port=443): Max retries exceeded with url: /link (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x000002669FF9B4D0>, 'Connection to video-oss.vercel.app timed out. (connect timeout=None)'))
作者: qqmqqg    时间: 2024-10-8 08:12
66666666666666666666666
作者: please    时间: 2024-10-8 09:38
感谢分享,支持开源!!!
作者: lxz159464    时间: 2024-10-10 05:35
感谢分享,支持开源!!!
作者: gdxinda    时间: 2024-10-10 10:18
感谢分享,支持开源!!!
作者: 熊不熊    时间: 2024-12-4 10:41
感谢分享,很给力!~




欢迎光临 精易论坛 (https://125.confly.eu.org/) Powered by Discuz! X3.4