带有cookie的Angular API httpClient请求,也包括Electron

2024-06-02 04:36:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在建立一个应用程序与电子和角度。你知道吗

目前正在使用可观测和角度HTTPclient

我想从api中获取一些数据,但是angular中出现了一个错误,因为我需要向其中添加cookie。你知道吗

def poe_get_data(userName, league, poesessid):
    baseURL = "https://www.pathofexile.com/character-window/get-stash-items?league={}&accountName={}&tabs={}"
    addinURL = "&tabIndex="
    probeURL = baseURL.format(league, userName, 1)
    probe = requests.get(probeURL, cookies=poesessid)
    probe.raise_for_status()

poeData = poe_get_data(accountName, league, cookie)

这是一个工作的python版本。你知道吗

我还尝试将pythonshell添加到angular中,但在.py脚本的路径位置上遇到了问题。它甚至与html在同一个.ts目录中,首先将它放在服务文件夹中。你知道吗

我知道flask可能会有帮助,但我还没有考虑将flask合并到electron中,因为我想为windows/mac/linux网络制作这个应用程序

任何建议都会有帮助。 我一直在使用httpclient

下面是我的服务的代码,现在从不同的源获取其他api数据,而不需要cookie:

private url= "https://cors-anywhere.herokuapp.com/https://poe.ninja/api/data/ItemOverview?league=Blight&type=Fossil";
  getPoeNinjaData(): Observable<any> {
    console.log("Fetching Data");
    // httpProvider.defaults.useXDomain = true;
    let getfromNinja = this.http.get<any>(this.url);
    // let getOurStash = this.http.get<any>("");
    return getfromNinja;
  }
import requests
url = (
    "https://www.pathofexile.com/character-window/get-stash-items?"
    "league=Blight&tabs=0&tabIndex=1,3&accountName=[accnamehere]"
)
payload = {'POESESSID': '[SESSID]'}
response = requests.post(url, cookies=payload)
print(response.status_code)
if response.status_code == 200:
    data = response.json()
    print(data)

这很管用

https://app.swaggerhub.com/apis/Chuanhsing/poe/1.0.0?loggedInWithGitHub=true#/Leagues

我需要设置用户为调用输入的POESESSID cookie。我只需要一个有效的存储响应并将其放入一个数据结构中,然后我就可以从那里开始了。你知道吗

谢谢你

抱歉,我对角度和电子开发非常陌生

这是我的回购协议 https://github.com/zombodotcom/Zombpoe/tree/StashFinderHelp


Tags: httpscomapiurldatagetcookieresponse