如何解决未经授权的请求(401响应)?

发布于 2025-01-26 01:13:10 字数 1980 浏览 4 评论 0原文

我正在尝试使用GET和发布方法从网站上进行一些刮擦,但是现在我面临着一个新的挑战。

我试图从信用模拟器中获取数据,我找到了这个葡萄牙网站( https:/https:/ /www.wizink.pt/public/credito-pessoal#/ )。

据我所知,我需要使用Post方法,但是我只能获得401响应

这是我的代码:

from openpyxl import load_workbook
import requests
import numpy as np
import time
from datetime import datetime
import pandas as pd
import json

import warnings
warnings.filterwarnings("ignore")

url_Wizink = 'https://www.creditopessoal.wizink.pt/gravitee/gateway/api-chn-loans/v1/loans/quotation'
            
headers_WiZink = {'Accept': 'application/json',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'pt-PT',
'Authorization': 'Bearer 978131ab-8acd-4671-bfaf-ae325d148adf',
'Connection': 'keep-alive',
'Content-Length': '266',
'Content-Type': 'application/json;charset=UTF-8',
'Host': 'www.creditopessoal.wizink.pt',
'Origin': 'https://www.wizink.pt',
'Referer': 'https://www.wizink.pt/',
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"',
'sec-ch-ua-mobile': '?0',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-site',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36',
'X-Channel-Id': 'LOANSIMULATOR',
'X-Client-Id': 'simWzkPt',
'X-Country-Id': 'PRT',
'X-Device-UUID': 'd14e9b629804cbba1ac7c3e78ab39a56'}
        
        
payload_Wizink = {"productCode":"WZP01","fixedTermLoanId":"0024","impositionAmount":{"amount":5500,"currency":"EUR"},"settlementDay":"5","dueOrAdvanceInterestIndicator":"3",
                  "nominalInterest":"8.0000000","feeRateId":"05","settlementFrequencyId":"0001","deprecationFrequencyId":"0001"}
        
response_Wizink = requests.post(url_Wizink, headers=headers_WiZink, data=payload_Wizink, verify=False)

关于问题是什么的想法?

I am trying to do some scraping from websites using GET and POST methods, but now I am facing a new challenge.

I am trying to get data from a credit simulator, I found this portuguese site (https://www.wizink.pt/public/credito-pessoal#/).

As far as I know, I need to use POST method,but I am only getting 401 for the response.

Here is my code:

from openpyxl import load_workbook
import requests
import numpy as np
import time
from datetime import datetime
import pandas as pd
import json

import warnings
warnings.filterwarnings("ignore")

url_Wizink = 'https://www.creditopessoal.wizink.pt/gravitee/gateway/api-chn-loans/v1/loans/quotation'
            
headers_WiZink = {'Accept': 'application/json',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'pt-PT',
'Authorization': 'Bearer 978131ab-8acd-4671-bfaf-ae325d148adf',
'Connection': 'keep-alive',
'Content-Length': '266',
'Content-Type': 'application/json;charset=UTF-8',
'Host': 'www.creditopessoal.wizink.pt',
'Origin': 'https://www.wizink.pt',
'Referer': 'https://www.wizink.pt/',
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"',
'sec-ch-ua-mobile': '?0',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-site',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36',
'X-Channel-Id': 'LOANSIMULATOR',
'X-Client-Id': 'simWzkPt',
'X-Country-Id': 'PRT',
'X-Device-UUID': 'd14e9b629804cbba1ac7c3e78ab39a56'}
        
        
payload_Wizink = {"productCode":"WZP01","fixedTermLoanId":"0024","impositionAmount":{"amount":5500,"currency":"EUR"},"settlementDay":"5","dueOrAdvanceInterestIndicator":"3",
                  "nominalInterest":"8.0000000","feeRateId":"05","settlementFrequencyId":"0001","deprecationFrequencyId":"0001"}
        
response_Wizink = requests.post(url_Wizink, headers=headers_WiZink, data=payload_Wizink, verify=False)

Any ideas on what the problem is?

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

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

发布评论

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

评论(1

叹倦 2025-02-02 01:13:10

这是一个请求。尝试更改帖子以获取。
它在邮递员的卷发中对我有用:

curl --location --request GET 'https://www.creditopessoal.wizink.pt/gravitee/gateway/api-chn-channel-services/v1/configuration' \
--header 'accept: application/json' \
--header 'authorization: Bearer c1da0022-5226-48e9-96dd-f40021310147' \
--header 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36' \
--header 'x-device-uuid: 4cb845ee7b2efc857838a28fa19aaa60'

It is a GET request. Try to change POST for GET.
It works for me in postman with this curl:

curl --location --request GET 'https://www.creditopessoal.wizink.pt/gravitee/gateway/api-chn-channel-services/v1/configuration' \
--header 'accept: application/json' \
--header 'authorization: Bearer c1da0022-5226-48e9-96dd-f40021310147' \
--header 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36' \
--header 'x-device-uuid: 4cb845ee7b2efc857838a28fa19aaa60'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文