I am using walmart partner api with python script. What I am trying to do is uploading item file using httplib. Here is my code:
file = open('/opt/item.xml', 'rb')
headers = {
"Accept":ws_accept,
"WM_SVC.NAME": wm_svc_name,
"WM_CONSUMER.ID":wm_consumer_id,
"WM_SEC.TIMESTAMP": wm_sec_timestamp,
"WM_SEC.AUTH_SIGNATURE":wm_sec_auth_signature,
"WM_QOS.CORRELATION_ID": wm_qos_correlation_id,
"Content-Type": 'multipart/form-data; boundary=xxx',
"Host":'marketplace.walmartapis.com'
}
conn = httplib.HTTPSConnection('marketplace.walmartapis.com')
conn.request("POST", '/v2/feeds?feedType=item',file, headers)
response = conn.getresponse()
print response.status, response.reason
print 'response',response.read()
item.xml is sample file available in documention.
Response is here:
500 Internal Server Error
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:errors xmlns:ns2="http://walmart.com/">
<ns2:error>
<ns2:code>SYSTEM_ERROR.GMP_GATEWAY_API</ns2:code>
<ns2:description>Couldn't find MIME boundary: --xxx</ns2:description>
<ns2:info>System encountered some internal error.</ns2:info>
<ns2:severity>ERROR</ns2:severity>
<ns2:category>DATA</ns2:category>
<ns2:causes/>
<ns2:errorIdentifiers/>
</ns2:error>
</ns2:errors>
Hope someone familiar with walmart partner api. Otherwise suggest with multipart-boundary error and how can I fix this please help guys...
From my personal experience, you may want to actually ask Walmart, "Have you received my file?" I have gotten 500s and 400s from them before with their other APIs and it has gone through the first run even though the API response code was not 200.
Related
Im trying to comment on a pull request using githubs api but I'm getting the error shown in the title. The only solutions that I've seen on stack overflow is to json.dumps the data but that did not resolve the problem for me. What could I be doing wrong?
Here is my code
def _pr_comment(self, res, pr_id):
# POST / repos /: owner /:repo / issues /: issue_number / comments
payload = {"body": json.dumps(res)}
header = {'Authorization': 'token TOKEN',
"Accept": "application/vnd.github.+json"}
response_decoded_json = requests.post(
f'https://api.github.com/repos/REPO/Database-System/issues/{pr_id}/comments',
data=payload, headers=header)
response_json = response_decoded_json.json()
print(response_json, response_decoded_json.status_code)
This is the full response that I receive along side the response code
{'message': 'Problems parsing JSON', 'documentation_url': 'https://developer.github.com/v3/issues/comments/#create-a-comment'} 400
Any help on this would be appreciated!
The error you're seeing relates to the payload which was submitted.
Assuming res contains a string which is the actual body of the comment, I think you need to run the whole payoad through json.dumps then provide this as the data param to requests.post. So change it to something like:
payload = json.dumps({"body": res})
The requests documentation actually contains an example, related to the github API.
I am just trying to access an API through Postman and its wokring fine.The Postman header response is returning some details like below
Authentication-Token →/DwG7gAxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Connection →keep-alive
Content-Length →16
Content-Type →application/json;charset=UTF-8
Date →Tue, 25 Sep 2018 17:44:01 GMT
Server →Apache-Coyote/1.1
But when I am trying to do same in Python I am just receivig the response status.(200)
How can I get the above Authentication-Token etc details like Postman in python code.
import requests
import json
url = 'https://test-orchestrator.lmig.com/baocdp/rest/login/'
headers = {"Content-Type": "application/json"}
data1 = {"username":"abc", "password":"abc"}
print("Testing authentication for Remedy test environment...")
change_response=requests.post(url,data=json.dumps(data1),headers=headers)
print(change_response)
If you print change_response, it will most likely look like this <status [200]> or something to that effect. If you want to see the contents of the response, you can use the vars response.text, response.content, or response.headers (among others) or since this is a json response, you can use the method response.json() to convert the contents of the response into a dictionary full of native Python data types.
I would reccommend x = response.json(), as the contents of your response seem to contain an auth token that you will most likely need to communicate with this device further. You can then use auth+token = x[token_key] to isolate that token.
I want to get the configuration of devices on my XProtect Corporate account, I am following this post
http://doc.developer.milestonesys.com/html/reference/protocols/imageserver_getdevices.html
but I am getting 401, unauthorized every time.
Until now I have managed to authenticate myself and got a token, now as i have the corporate account, I will need to send the token for the authorization, I am using requests lib in python to send a GET request like this
head = {'Authorization': 'Token {}'.format(myToken)}
response = requests.get('http://server-ip/rcserver/sysmteminfo.xml', headers=head)
print response
I am not sure about how to send my token in this get request
Any help will be highly appreciated
So I finally able to get the configuration of all the devices on the server. Problem was, the above approach works for XProtect Enterprise and XProtect Professional only, if you have an XProtect Corporate, you need a NTLM authentication and you have to call GetConfiguration function on the Server SOAP protocol.
r2= '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetConfiguration xmlns="http://videoos.net/2/XProtectCSServerCommand"><token>' + str(myToken) + '</token></GetConfiguration></soap:Body></soap:Envelope>'
data_len = str(len(r2))
s.sendall("POST /ManagementServer/ServerCommandService.svc HTTP/1.1\r\nHost: server-ip\r\nContent-Type: text/xml; charset=utf-8\r\nAuthorization: Basic (base64 encoded '*[BASIC]\username:password*')\r\nContent-Length: "+data_len+"\r\nSOAPAction: http://videoos.net/2/XProtectCSServerCommand/IServerCommandService/GetConfiguration\r\n\r\n"+ r2)
I’m trying to connect to the OPS API but get an error when trying to connect to the url. I get the access_token just fine as detailed in the documentation (page 34), but when I try to connect to the url I’m interested in, I get a ‘Name or Service not found’ error.
The documentation states (page 35) that the client should access the OPS resource over an encrypted HTTPS connection, which I think might be the missing step in my code creating this error (or not).
Below is the code I use (replacing #### with my access_token):
from http.client import HTTPSConnection
c = HTTPSConnection('ops.epo.org/3.2/rest-services/published-data/search?q=Automation', port=443)
headers2 = {'Authorization': ‘Bearer ########kv5’}
c.request('GET', '/', headers=headers2)
res = c.getresponse()
data = res.read()
Many thanks.
Not sure why this issue was happening earlier, but it seems to be fine now when I run the following code:
headers = {'Authorization': 'Bearer %s' % token }
query = requests.get('http://ops.epo.org/3.2/rest-services/published-data/search?q=Automation', headers=headers)
query.content
I get a status response code of 200, and I can parse the content just fine.
I'm trying to make a getmyebayselling request so I can track the prices and quantities of current listings.
Following the docs and sample here I generated a token and tried sending a request to the production XML to see my current listings.
Current attempt:
endpoint = "https://api.ebay.com/ws/api.dll"
xml = """<?xml version="1.0" encoding="utf-8"?>
<GetMyeBaySellingRequest xmlns="urn:ebay:apis:eBLBaseComponents">
<RequesterCredentials>
<eBayAuthToken>AgAAAA*...full auth token here...wIAYMEFWl</eBayAuthToken>
</RequesterCredentials>
<Version>967</Version>
<ActiveList>
<Sort>TimeLeft</Sort>
<Pagination>
<EntriesPerPage>3</EntriesPerPage>
<PageNumber>1</PageNumber>
</Pagination>
</ActiveList>
</GetMyeBaySellingRequest>"""
headers = {'Content-Type': 'application/xml'}
response = requests.post(endpoint, data=xml, headers=headers)
print response
print response.content
The response:
<?xml version="1.0" encoding="UTF-8" ?><GeteBayOfficialTimeResponse xmlns="urn:ebay:apis:eBLBaseComponents"><Timestamp>2017-04-17 13:01:25</Timestamp><Ack>Failure</Ack><Errors><ShortMessage>Unsupported API call.</ShortMessage><LongMessage>The API call "GeteBayOfficialTime" is invalid or not supported in this release.</LongMessage><ErrorCode>2</ErrorCode><SeverityCode>Error</SeverityCode><ErrorClassification>RequestError</ErrorClassification></Errors><Build>18007282</Build></GeteBayOfficialTimeResponse>
The useful part of that response:
The API call "GeteBayOfficialTime" is invalid or not supported in this release.
I'm working from a sample of their own docs here. The only link to time I could really see was <Sort>TimeLeft</Sort> which was a stretch but even without that I get the same response.
I was faffing around with different Python libs trying to get a getmyebayselling request working without much documentation. Now going by the docs from eBay themselves I'm feeling pretty dead in the water. If anyone can nudge me in the right direction I'd appreciate it. Not really sure what to try next.
The API response error is a little less than helpful, but judging by the code you shared you are making the request with missing required header fields. More details here
The following change should point you in the right direction -
headers = {
'X-EBAY-API-COMPATIBILITY-LEVEL': '<compat_level>',
'X-EBAY-API-CALL-NAME': '<api_call_name>',
'X-EBAY-API-SITEID': '<api_siteid>',
'Content-Type': 'application/xml'
}
Suddenly I started getting the error message:
The API call "GeteBayOfficialTime" is invalid or not supported in this release.
But I was not calling GeteBayOfficialTime! I had a problem, but the error message was misleading.
To make sure you get the post headers and content right, the build test tool is absolutely helpful:
ebay developer build test tool
After hours of troubleshooting, I finally figured out my problem: I was passing the required headers in the query string, not as http request headers! For over a year, it worked OK, but then suddenly it stopped working.
Moral: the invalid "GeteBayOfficialTime" API call message indicates a problem with the http headers.