n/programu/defaultuser6 · 2025-02-10
Registrati Accedi
n/program · 2025-02-10 · 352 visualizzazioni
u/defaultuser6Argento

求助NodeLoc站内发送私信(python)

```
import httpx

class NodeLoc():
def init(self):
self.cli=httpx.Client(base_url="https://nodeloc.com/",headers={
"user-agent":"NLPay/0.1"
},follow_redirects=True)
self.update_csrf()

def update_csrf(self):
    self.cli.headers["x-csrf-token"]=self.cli.get("/").headers["x-csrf-token"]
    return self.cli.headers["x-csrf-token"]

def login(self,token):
    self.cli.cookies["flarum_remember"]=token
    data=self.cli.get("/api/user").json()
    self.uid=data["id"]
    self.uname=data["username"]

def get_uid_by_username(self,username):
    resp=self.cli.get("/api/posts",params={
        "filter[author]":username,
        "filter[type]":"comment",
        "page[offset]":0,
        "page[limit]":1
    })
    resp.raise_for_status()
    data=resp.json()["data"]
    if len(data)==0:
        return None
    else:
        return data[0]["relationships"]["user"]["data"]["id"]

class Messenger(NodeLoc):
def send(self,to,content):
self.update_csrf()
resp=self.cli.post("/api/whisper/conversations",
json={"data":
{
"type":"conversations",
"attributes":{"messageContents":content,"recipient": str(to)}
}}
)
return resp
```
这是代码,API自行抓包获得,现在的问题上send()函数调用之后会重定向成get请求,然后返回200,但是没有创建;前端抓包是返回201.

0
1
Accedi per partecipare alla discussione.
海外原生IP VPS,稳定访问全球网络

还在为IP不纯、平台风控、频繁验证而烦恼? 丽萨主机海外原生IP VPS,双ISP住宅IP,覆盖美国、香港、日本、新加坡、台湾、德国、越南、英国等热门地区,适合跨境电商、社媒运营、AI工具、流媒体及海外业务使用。

lisahost.com Scopri di più

1 risposte

Ordinamento
  1. dfjk Platino 2025-02-10

    测试的时候先把 Headers 和 Payload 全按浏览器抓下来的设置一遍 Send 过去看看成功不成功。

    0