首页 新闻 会员 周边 捐助

metaweblog报错

0
[已解决问题] 解决于 2022-12-11 21:26

url = server.metaWeblog.newMediaObject(conf["blog_id"], conf["username"], conf["password"], file)

我在使用API上传文件时报错:

Traceback (most recent call last):
File "upload.py", line 55, in <module>
asyncio.run(upload_tasks(local_images))
File "C:\ProgramData\Anaconda3\lib\asyncio\runners.py", line 43, in run
return loop.run_until_complete(main)
File "C:\ProgramData\Anaconda3\lib\asyncio\base_events.py", line 583, in run_until_complete
return future.result()
File "upload.py", line 44, in upload_tasks
await asyncio.gather(*tasks)
File "C:\ProgramData\Anaconda3\lib\asyncio\events.py", line 88, in _run
self._context.run(self._callback, *self._args)
File "upload.py", line 27, in get_image_url
url = t.result()['url']
File "C:\Users\Administrator\Desktop\pycnblog-master\pycnblog-master\img_transfer.py", line 35, in upload_img
url = server.metaWeblog.newMediaObject(conf["blog_id"], conf["username"], conf["password"], file)
File "C:\ProgramData\Anaconda3\lib\xmlrpc\client.py", line 1112, in call
return self.__send(self.__name, args)
File "C:\ProgramData\Anaconda3\lib\xmlrpc\client.py", line 1452, in __request
verbose=self.__verbose
File "C:\ProgramData\Anaconda3\lib\xmlrpc\client.py", line 1154, in request
return self.single_request(host, handler, request_body, verbose)
File "C:\ProgramData\Anaconda3\lib\xmlrpc\client.py", line 1170, in single_request
return self.parse_response(resp)
File "C:\ProgramData\Anaconda3\lib\xmlrpc\client.py", line 1342, in parse_response
return u.close()
File "C:\ProgramData\Anaconda3\lib\xmlrpc\client.py", line 656, in close
raise Fault(**self._stack[0])
xmlrpc.client.Fault: <Fault 1: '上传失败, Response status code does not indicate success: 403 (Forbidden).'>

xmlrpc.client.Fault: <Fault 1: '上传失败, Response status code does not indicate success: 403 (Forbidden).'>

我看服务端返回了403 forbidden禁止了,这个什么原因??

Leo101018的主页 Leo101018 | 菜鸟二级 | 园豆:202
提问于:2022-12-11 17:15
< >
分享
最佳答案
0

应该有对应的 response body,建议打印出来看一下

现在 metaweblog api 不支持密码登录,需要在博客后台获取 access token 作为密码

奖励园豆:5
dudu | 高人七级 |园豆:29759 | 2022-12-11 17:18

你好:
配置文件中确实是使用的token令牌作为的密码。
但是,我追踪代码,是执行到如下代码的
url = server.metaWeblog.newMediaObject(conf["blog_id"], conf["username"], conf["password"]
这条语句之后,就可以报错了,后续print(url)没有执行到。这个可能是服务端API导致的么??客户端这边已经没有什么可以操作的了。
感谢回复!!!
with open(path, 'rb') as f:
file = {
"bits": f.read(),
"name": name,
"type": mime_mapping[suffix]
}
url = server.metaWeblog.newMediaObject(conf["blog_id"], conf["username"], conf["password"], file)
print(url)
return url

Leo101018 | 园豆:202 (菜鸟二级) | 2022-12-11 17:23

你好:
而且很奇怪的问题是,同样的代码,昨天还好使,刚才突然就不能用了!!!

Leo101018 | 园豆:202 (菜鸟二级) | 2022-12-11 17:27

@Leo101018: 是因为超过了1天上传图片数的限制

dudu | 园豆:29759 (高人七级) | 2022-12-11 17:47

@dudu: 哦哦,原来是这样,看来是服务端API的限制了,多谢多谢!!

Leo101018 | 园豆:202 (菜鸟二级) | 2022-12-11 21:23
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册