Python code generated by Insomnia GraphQL client reacts not as expected

主宰稳场 提交于 2020-08-10 19:21:03

问题


I've an issue with the python code generated by Insomnia with submitting GraphQL queries to Shopify with Umlauts. When using the Insomnia client the query is executed as expected

When using the insomnia generated code with Python 3.x on Mac (tried both command line execution as well as Jupyter), the Umlaut doesn't get displayed correctly:

Here's the Python code:

import requests

url = "https://langerchen.myshopify.com/admin/api/2020-07/graphql.json"

payload = "{\"query\":\"mutation($input: ProductInput!) {\\n  productUpdate(input: $input) 
{\\n    product {\\n      metafields(first: 100) {\\n        edges {\\n          node {\\n            
id\\n            namespace\\n            key\\n            value\\n          }\\n        
}\\n      }\\n    }\\n  }\\n}  \",\"variables\":{\"input\": 
{\"id\":\"gid://shopify/Product/5438127669399\",\"metafields\":[{\"namespace\":\"product- 
details\",\"key\":\"Style\",\"value\":\"This should display a umlaut: 
Ü\",\"valueType\":\"STRING\"}]}}}"
headers = {
    'cookie': "_secure_admin_session_id=xxx; 
     _secure_admin_session_id_csrf=xxx; request_method=POST; 
     __cfduid=xxx",
     'x-shopify-access-token': "shppa_xxx",
     'content-type': "application/json"
     }
    
response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)

The response:

{"data":{"productUpdate":{"product":{"metafields":{"edges":[{"node": 
{"id":"gid:\/\/shopify\/Metafield\/14509735084183","namespace":"product- 
details","key":"Style","value":"This should display a umlaut: Ü"}},{"node": 
{"id":"gid:\/\/shopify\/Metafield\/14509782761623","namespace":"product- 
details","key":"Kurzbeschreibung","value":"This should display a umlaut: 
�"}}]}}}},"extensions":{"cost": 
{"requestedQueryCost":112,"actualQueryCost":14,"throttleStatus": 
{"maximumAvailable":1000.0,"currentlyAvailable":986,"restoreRate":50.0}}}}

I am also including the Screenshot of Shopify displaying both cases, Python on the left, Insomnia on the right.

来源:https://stackoverflow.com/questions/63141535/python-code-generated-by-insomnia-graphql-client-reacts-not-as-expected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!