如何将API打印与Django连接

发布于 2025-02-02 21:06:52 字数 484 浏览 1 评论 0原文

我在与Django连接到Printify API时遇到了问题,我不是很实用,因此我需要理解为什么要通过参数

视图来传递的原因:

def home(request):
    token = settings.TOKEN_PRINTIFY
    headers = {'Content-Type': 'application/json', 'Authorization' : 'Bearer ' + token}
    response = requests.get('https://api.printify.com/v1/shops', headers = headers)
    print('-----------------', response) #error 404

    context = {}
    return render(request, 'home.html', context)

它的响应使我允许我401状态,我不明白在哪里放置那个象征

I have problems connecting to the printify api with django, I am not very practical so I would need to understand why and above all what to pass as parameters

views:

def home(request):
    token = settings.TOKEN_PRINTIFY
    headers = {'Content-Type': 'application/json', 'Authorization' : 'Bearer ' + token}
    response = requests.get('https://api.printify.com/v1/shops', headers = headers)
    print('-----------------', response) #error 404

    context = {}
    return render(request, 'home.html', context)

the response it gives me how 401 status and I don't understand where to put that token

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半寸时光 2025-02-09 21:06:52

这些不是参数,而是标题
替换params =有效载荷 by:

{headers: {'Content-Type': 'application/json', Authorization : 'Bearer ' + token}}

These are not params but headers
replace params=payload by:

{headers: {'Content-Type': 'application/json', Authorization : 'Bearer ' + token}}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文