Почему мои вызовы Python POST возвращают 404? - PullRequest
0 голосов
/ 30 мая 2018

Я пытаюсь разместить новый продукт на API fetchapp (REST API) с Python.Тем не менее, я читал документацию по API и пытался понять, но я получаю ошибку 404.Это то, что говорит API документ, и это то, что у меня есть.

Документ API:

All requests require basic authentication. To make a proper request,
you must set the authorization header of your request and supply
the generated string. The string is your personal key and token with
a colon ("demokey:demotoken") converted to a base-64 string. For
example...

"demokey:demotoken".to_base64 is ZGVtb2tleTpkZW1vdG9rZW4=

Then, place the string into the authorization header of your HTTP requests...

GET /api/v2/orders HTTP/1.1
Host: app.fetchapp.com
Authorization: Basic ZGVtb2tleTpkZW1vdG9rZW4=
Content-Type: application/xml

Please make sure to set the Content-Type header to 'application/xml'.

POST to create the specified product...

/api/v2/products
/api/v2/products/create
/api/v2/products/create.xml
For example...

<?xml version="1.0" encoding="UTF-8"?>
<product>
    <sku>1</sku>
    <name>Carrot Juice</name>
    <price type="float">10.00</price>
    <files type="array">
        <id>4443443</id>
        <id>4443444</id>
    </files>
</product>

Что у меня есть:

from requests_oauthlib import OAuth1Session
import requests
from requests_oauthlib import OAuth1
import json
from oauthlib.oauth1 import SIGNATURE_TYPE_QUERY, SIGNATURE_TYPE_BODY
from requests_toolbelt import MultipartEncoder
import time
from requests.auth import HTTPBasicAuth


url = 'http://www.fetchapp.com/api/v2/products/create.xml' 
headers = {"Accept": "application/xml"} 

auth=HTTPBasicAuth('demokey', 'demotoken')
data = {'sku': "CJ0001", 'name': "Carrot Juice", 'price type="float"': "1.00"}
r = requests.post(url, auth=auth, headers=headers, data=data, verify=True)

print r#.text
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...