【发布时间】:2021-12-04 22:51:17
【问题描述】:
我正在 django 中创建自定义命令。我在使用 fromtimestamp 等方法将时间戳转换为日期时遇到问题。我有这样的错误: 第 13 行,在句柄中 timest_conv = datetime.fromtimestamp(timest) OSError: [Errno 22] 无效参数
这是我的带把手的课
class Command(BaseCommand):
def handle(self, *args , **options):
r = requests.get('https://api.metals.live/v1/spot/silver').json()
price = r[0]['price']
timest = r[0]['timestamp']
timest_conv = datetime.fromtimestamp(timest)
print(price,timest, timest_conv )
return
【问题讨论】:
-
r[0]['timestamp']是什么样的? -
最后一个1634309968403
-
当我将它转换为 int(r[0]['timestamp']) 错误是一样的
标签: python django add-custom-command