comwrg / bilibiliupload

This project is not maintained anymore.
MIT License
140 stars 35 forks source link

当上传多个视频的时候cover_up报错 #33

Closed haiyunx closed 5 years ago

haiyunx commented 5 years ago

Describe the bug 当上传多个视频的时候cover_up报错

Your code

def BiliUpload(csv_dict,b_zhan):

    video_cnt = 0
    total = len(csv_dict)
    for line in csv_dict:
        video_cnt += 1
        video_name, video_desc, title = line['视频名称'], line['视频介绍'], line['投稿标题']
        tid, tags, desc = line['分区号'], line['标签'], line['投稿简介-250以内']
        cover, source = line['封面'], line['来源']

        if cover is None:
            cover = '';

        if source is None:
            source = '';
        tid = int(tid)

        try:
            tags.split(";")
        except ValueError:
            tagLists = {tags}
        else:
            tagLists = tags.split(";")
        videoPart = VideoPart(video_name, video_desc) #or[VideoPart(…), VideoPart(…)]
        #publishTime = '2019-07-04 20:00:00'
        #publishTimeUnixLocal = int(datetime.datetime.strptime(publishTime, '%Y-%m-%d %H:%M:%S').strftime("%s"))

        print("** 开始上传第 %d 个视频 - %s" % (video_cnt, title,))
        upload_msg = b_zhan.upload(
            parts = videoPart,
            title = title,
            tid = tid, #其他-生活
            tag = tagLists,
            desc = desc,
            cover = b_zhan.cover_up(cover), #(optional)
            source = source #(optional)
            #dtime= publish_time, #(optional) 投稿时间
            #no_reprint= 1, #(optional) 0=可以转载, 1=禁止转载(default)
            #open_elec= 1, #(optional) 1=启用充电面板(default) 0=禁止
            #max_retry = 2 #(optional)max 5 max retry times per chunk
        )
        if video_cnt != total
            print("****【上传结果见上】")
            print("** 等待60秒")
            sleep(60)

    return video_cnt

Error message

** 读取csv文件
**** 【已读取】 2 行
** 正在登陆B站
**** 【成功】用户名XXX
** 开始上传第 1 个视频 - 岳云鹏搞笑片段2222
http://i0.hdslb.com/bfs/archive/dd7f4dfa464360c479b3ecdb1e00f2bcfffbe62f.jpg
0/7 MULTIPART_PUT_SUCCESS
1/7 MULTIPART_PUT_SUCCESS
2/7 MULTIPART_PUT_SUCCESS
3/7 MULTIPART_PUT_SUCCESS
4/7 MULTIPART_PUT_SUCCESS
5/7 MULTIPART_PUT_SUCCESS
6/7 MULTIPART_PUT_SUCCESS
{"code":0,"message":"0","ttl":1,"data":{"aid":57889848}}
****【上传结果见上】
** 等待40秒
** 开始上传第 2 个视频 - 明星大侦探3收官2222
Traceback (most recent call last):
  File "test.py", line 83, in <module>
    uploadCnt = BiliUpload(user,password,csvDict,bili)
  File "test.py", line 57, in BiliUpload
    cover_fix = b_zhan.cover_up(cover)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/bilibiliupload/bilibili.py", line 406, in cover_up
    return r.json()['data']['url']
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/models.py", line 897, in json
    return complexjson.loads(self.text, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
HelenaXdeMacBook-Pro:pythonScripts helenax$ python3 test.py

不使用cover_up则没有这个问题

** 正在登陆B站
**** 【成功】用户名XXX
** 读取csv文件
**** 【已读取】 2 行
** 开始上传第 1 个视频 - 岳云鹏搞笑片段777
0/7 MULTIPART_PUT_SUCCESS
1/7 MULTIPART_PUT_SUCCESS
2/7 MULTIPART_PUT_SUCCESS
3/7 MULTIPART_PUT_SUCCESS
4/7 MULTIPART_PUT_SUCCESS
5/7 MULTIPART_PUT_SUCCESS
6/7 MULTIPART_PUT_SUCCESS
{"code":0,"message":"0","ttl":1,"data":{"aid":57890160}}
****【上传结果见上】
** 等待40秒
** 开始上传第 2 个视频 - 明星大侦探3收官777
0/11 MULTIPART_PUT_SUCCESS
1/11 MULTIPART_PUT_SUCCESS
2/11 MULTIPART_PUT_SUCCESS
3/11 MULTIPART_PUT_SUCCESS
4/11 MULTIPART_PUT_SUCCESS
5/11 MULTIPART_PUT_SUCCESS
6/11 MULTIPART_PUT_SUCCESS
7/11 MULTIPART_PUT_SUCCESS
8/11 MULTIPART_PUT_SUCCESS
9/11 MULTIPART_PUT_SUCCESS
10/11 MULTIPART_PUT_SUCCESS
{"code":0,"message":"0","ttl":1,"data":{"aid":57890265}}
****【上传结果见上】
comwrg commented 5 years ago

image 上传代码应该是没问题,看看是不是传进来的参数有问题

haiyunx commented 5 years ago

我今早又测试了 一下 好像也不是 csv file的问题 csv file

视频名称,视频介绍,投稿标题,分区号,标签,投稿简介-250以内,封面,来源, 投稿时间
测试.mp4,这是一个测试,岳云鹏搞笑片段test1,174,马云;演讲;激情,这是一个测试投稿,测试.jpg,http://www.youtube.com,
明星大侦探3收官.mp4,明星大侦探3,明星大侦探3收官test1,174,明星大侦探,这是一个测试投稿2,2.jpg,http://www.youtube.com,

print了一下参数

** 正在登陆B站
**** 【成功】用户名XXX
** 读取csv文件
**** 【已读取】 2 行
** 开始上传第 1 个视频 - 岳云鹏搞笑片段test1
<bilibiliupload.bilibili.VideoPart object at 0x10c0a4dd8> 岳云鹏搞笑片段test1 174 ['马云', '演讲', '激情'] 这是一个测试投稿 测试.jpg http://www.youtube.com
****【上传结果见上】
** 开始上传第 2 个视频 - 明星大侦探3收官test1
<bilibiliupload.bilibili.VideoPart object at 0x10c0a4630> 明星大侦探3收官test1 174 ['明星大侦探'] 这是一个测试投稿2 2.jpg http://www.youtube.com
【完成】处理 2 件投稿
haiyunx commented 5 years ago

image 上传代码应该是没问题,看看是不是传进来的参数有问题

红框里是我之前print 了一下cover_up的返回结果,是我上传第一个视频的测试封面的一个url

comwrg commented 5 years ago

v0.1.6 并且在开始加上这两句

import logging
logging.basicConfig(level=logging.DEBUG)

我看下log

haiyunx commented 5 years ago

找到原因了 加了一行 self.session.headers['Content-Type'] = 'application/x-www-form-urlencoded'