将 php 转换为 python base64

convert php to python base64

我有以下代码:

$url = 'https://website.com';

$cookie = 'Cookie: somecookies';

    $postData = 'somedata=6970001596407188738';
    
    
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, "https://ppi.com/api/req?apikey=23575e11111111111111129912");
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, "postdata=" . base64_encode($postData) . "&cookie=" . $cookie. "&url=" . base64_encode($url));
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    $result = curl_exec($curl);
    curl_close($curl);
    $sonuc = json_decode($result, true);
    
    if($sonuc["status"] == "ok") {

它显然是一个 post 请求,但我坚持这一部分:

import base64
print(base64.b64encode(bytes('your string', 'utf-8')))

它一直给我 b'eW91ciBzdHJpbmc=' (b) 值,如何在 python.

中删除它

我希望有人能帮我转换这段代码。到 python 请求。

谢谢, 问候

像这样解码你的字节:

import base64
print(base64.b64encode(bytes('your string', 'utf-8')).decode('utf-8'))
# eW91ciBzdHJpbmc=