使用html特殊字符和西里尔文进行POST/PUT

2024-04-16 17:43:23 发布

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

我正在尝试创建Python脚本来更新Woo商业商店中的产品。医生建议使用卷发:

curl -X PUT https://example.com/wc-api/v2/products/546 \
    -u consumer_key:consumer_secret \
    -H "Content-Type: application/json" \
    -d '{
  "product": {
    "regular_price": "24.54"
  }
}'

因为我使用的是python,所以我使用的是请求:

创造产品特性:

new={}
new['id']=555
new['regular_price'] = 1000
new['variations']=[]
new['attributes']=[{'name':'varatt1','variation':True,'options':['opt1','opt2']},{'name':'varatt2','variation':True,'options':['opt11','opt22']}]
new['type']='variable'
var1={}
var1['id']='111'
var1['attributes']=[{'name':'varatt1','option':'opt1'},{'name':'varatt2','option':'opt11'}]
new['variations'].append(var1)

json“new”并通过post发送:

f=json.dumps({'product':new})
header = {"Content-Type": "application/json"}
a=requests.put('http://endpoint?authstuff = done, data = f, headers = header)

问题

对于纯拉丁字符,一切都很好,但是如果我尝试使用西里尔字母来表示变体,结果是不可预测的——有时效果很好,有时数据部分丢失。第二个问题是,如果我试图发送,比方说,所有这些标签的描述-他们也会完全失去。你知道吗

我知道这里的问题在于编码,但是我用base64做的实验没有给我任何帮助。还尝试在所有西里尔文字符串上使用unquote-没有结果。相关问题:有没有可能放弃所有这些api的东西,直接编辑Woo commerce数据库?你知道吗


Tags: nameapiidjsonnewapplicationconsumer产品