深度学习,深度睡眠 2022-09-21 19:01 采纳率: 68.8%
浏览 29
已结题

python相同代码一个报错,一个正常运行

下图中左右两个代码一模一样,为什么左边报类型错误,右边正常运行?我觉得可能和append函数有关,左边那个是白色的,右边的是黄色的,但是代码都一样,为啥会这样,关闭重启都不行

img

左边代码:

import hashlib,time,base64,requests
from typing import List, Any

INDEX_URL = 'https://spa6.scrape.center/api/movie/?limit={limit}&offset={offset}&token={token}'
LIMIT = 10
OFFSET = 0

def get_token(args: List(Any)):
    timestamp = str(int(time.time()))
    args.append(timestamp)
    sign = hashlib.sha1(','.join(args).encode('utf-8')).hexdigest()
    return base64.b64encode(','.join([sign,timestamp]).encode('utf-8')).decode('utf-8')

args = ['/api/movie']
token = get_token(args=args)
index_url = INDEX_URL.format(limit=LIMIT,offset=OFFSET,token=token)
response = requests.get(index_url)
print('response:',response.json())

右边代码:


import hashlib
import time
import base64
from typing import List, Any
import requests

INDEX_URL = 'https://spa6.scrape.center/api/movie/?limit={limit}&offset={offset}&token={token}'
LIMIT = 10
OFFSET = 0

def get_token(args: List[Any]):
    timestamp = str(int(time.time()))
    args.append(timestamp)
    sign = hashlib.sha1(','.join(args).encode('utf-8')).hexdigest()
    return base64.b64encode(','.join([sign, timestamp]).encode('utf-8')).decode('utf-8')


args = ['/api/movie']
token = get_token(args=args)
index_url = INDEX_URL.format(limit=LIMIT, offset=OFFSET, token=token)
response = requests.get(index_url)
print('response', response.json())
  • 写回答

2条回答 默认 最新

  • Jackyin0720 2022-09-21 19:27
    关注

    img


    左边代码第8行:def get_token(args: List(Any)):这里存在错误,要改成这个:def get_token(args: List[Any]):
    【如有帮助,恭请采纳】

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 9月29日
  • 已采纳回答 9月21日
  • 创建了问题 9月21日