我对python有点陌生,我试图在django项目中使用一个序列化器类序列化的外部api,我得到以下错误
Traceback (most recent call last):
File "lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args,**callback_kwargs)
TypeError: __init__() takes 1 positional argument but 2 were given
"GET /project/v1/mypath/ HTTP/1.1" 500 56241
请看下面我的观点
import requests as requests
from rest_framework import viewsets
from rest_framework.response import Response
from .config import *
from .serializer import *
BASE_URL = BASE_URL
ACCOUNT_URL = "{}/v2/account".format(BASE_URL)
ORDERS_URL = "{}/v2/orders".format(BASE_URL)
HEADERS = {'APCA-API-KEY-ID': API_KEY, 'APCA-API-SECRET-KEY': SECRET_KEY}
# Create your views here.
class AlpacaGetAccountView(viewsets.ModelViewSet):
serializer_class = AlpacaAccountSerializer
queryset = AlpacaAccount.objects.all()
def get_account(self):
r = requests.get(ACCOUNT_URL, headers=HEADERS)
serializer = AlpacaAccountSerializer(r, many=True)
return Response(serializer.data)
Honestly, I have no idea where the error is coming from
Please advise me on how I can resolve this and where the error is coming from
还有哪个 __init__()
错误是指什么?
编辑我编辑了问题中的代码@bdbd提出的建议现在只返回空数组([])
请告诉我如何实际获取数据
暂无答案!
目前还没有任何答案,快来回答吧!