Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 通过REST向PrestaShop添加产品时发生XML解析器错误_Php_Python_Python 3.x_Prestashop - Fatal编程技术网

Php 通过REST向PrestaShop添加产品时发生XML解析器错误

Php 通过REST向PrestaShop添加产品时发生XML解析器错误,php,python,python-3.x,prestashop,Php,Python,Python 3.x,Prestashop,我试图在Python3中创建简单的GUI,以便将产品添加到商店中。 这是代码的一部分: def send(self): out = self.request('api/products?schema=blank', self.api_key.text(), 0) empty_xml = ET.fromstring(out) xml = self.InsertIntoXML(empty_xml, "test", 0) #xml = dump(xml)

我试图在Python3中创建简单的GUI,以便将产品添加到商店中。 这是代码的一部分:

 def send(self):

    out = self.request('api/products?schema=blank', self.api_key.text(), 0)

    empty_xml = ET.fromstring(out)

    xml = self.InsertIntoXML(empty_xml, "test", 0)
    #xml = dump(xml)

    xml = ET.tostring(xml, encoding='utf8', method='xml')
    print(xml)
    out = self.request('products', self.api_key.text(), xml)
    print (out)
def request(self, url, key, POST):
    username = 'kluczyk'
    password = ''
    api_root = 'http://192.168.1.43/api/'

    passman = urllib.request.HTTPPasswordMgrWithDefaultRealm()
    passman.add_password(None, api_root, username, password)
    authhandler = urllib.request.HTTPBasicAuthHandler(passman)
    opener = urllib.request.build_opener(authhandler)
    urllib.request.install_opener(opener)

    if POST == 0:
        url = api_root + url
        response = urllib.request.urlopen(url).read()
    else:
        url = api_root + url
        params = urllib.parse.urlencode({'XML': POST})
        params = params.encode('utf-8')
        try:
            response = urllib.request.urlopen(url, params).read()
        except HTTPError as e:
            response = e.read()


    return response
不幸的是,我总是得到这样的答案:

`<?xml version="1.0" encoding="UTF-8"?>\n<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">\n<errors>\n<error>\n<code><![CDATA[127]]></code>\n<message><![CDATA[XML error : String could not be parsed as XML\nXML length : 3379\nOriginal XML : XML=%3C%3Fxml+version%3D%271.0%27+encoding%3D%27utf8%27%3F%3E%0A%3Cprestashop%3E%0A%3Cproduct%3E%0A%09%3Cid+%2F%3E%0A%09%3Cid_manufacturer+%2F%3E%0A%09%3Cid_supplier+%2F%3E%0A%09%3Cid_category_default+%2F%3E%0A%09%3Cnew+%2F%3E%0A%09%3Ccache_default_attribute+%2F%3E%0A%09%3Cid_default_image+%2F%3E%0A%09%3Cid_default_combination+%2F%3E%0A%09%3Cid_tax_rules_group+%2F%3E%0A%09%3Ctype+%2F%3E%0A%09%3Cid_shop_default+%2F%3E%0A%09%3Creference+%2F%3E%0A%09%3Csupplier_reference+%2F%3E%0A%09%3Clocation+%2F%3E%0A%09%3Cwidth+%2F%3E%0A%09%3Cheight+%2F%3E%0A%09%3Cdepth+%2F%3E%0A%09%3Cweight+%2F%3E%0A%09%3Cquantity_discount+%2F%3E%0A%09%3Cean13+%2F%3E%0A%09%3Cupc+%2F%3E%0A%09%3Ccache_is_pack+%2F%3E%0A%09%3Ccache_has_attachments+%2F%3E%0A%09%3Cis_virtual+%2F%3E%0A%09%3Con_sale+%2F%3E%0A%09%3Conline_only+%2F%3E%0A%09%3Cecotax+%2F%3E%0A%09%3Cminimal_quantity+%2F%3E%0A%09%3Cprice+%2F%3E%0A%09%3Cwholesale_price+%2F%3E%0A%09%3Cunity+%2F%3E%0A%09%3Cunit_price_ratio+%2F%3E%0A%09%3Cadditional_shipping_cost+%2F%3E%0A%09%3Ccustomizable+%2F%3E%0A%09%3Ctext_fields+%2F%3E%0A%09%3Cuploadable_files+%2F%3E%0A%09%3Cactive+%2F%3E%0A%09%3Credirect_type+%2F%3E%0A%09%3Cid_product_redirected+%2F%3E%0A%09%3Cavailable_for_order+%2F%3E%0A%09%3Cavailable_date+%2F%3E%0A%09%3Ccondition+%2F%3E%0A%09%3Cshow_price+%2F%3E%0A%09%3Cindexed+%2F%3E%0A%09%3Cvisibility+%2F%3E%0A%09%3Cadvanced_stock_management+%2F%3E%0A%09%3Cdate_add+%2F%3E%0A%09%3Cdate_upd+%2F%3E%0A%09%3Cmeta_description%3E%3Clanguage+id%3D%221%22+%2F%3E%3C%2Fmeta_description%3E%0A%09%3Cmeta_keywords%3E%3Clanguage+id%3D%221%22+%2F%3E%3C%2Fmeta_keywords%3E%0A%09%3Cmeta_title%3E%3Clanguage+id%3D%221%22+%2F%3E%3C%2Fmeta_title%3E%0A%09%3Clink_rewrite%3E%3Clanguage+id%3D%221%22%3E%2528nowa%2529PS3%3C%2Flanguage%3E%3C%2Flink_rewrite%3E%0A%09%3Cname%3E%3Clanguage+id%3D%221%22%3E%28nowa%29%3C%2Flanguage%3E%3C%2Fname%3E%0A%09%3Cdescription%3E%3Clanguage+id%3D%221%22+%2F%3E%3C%2Fdescription%3E%0A%09%3Cdescription_short%3E%3Clanguage+id%3D%221%22+%2F%3E%3C%2Fdescription_short%3E%0A%09%3Cavailable_now%3E%3Clanguage+id%3D%221%22+%2F%3E%3C%2Favailable_now%3E%0A%09%3Cavailable_later%3E%3Clanguage+id%3D%221%22+%2F%3E%3C%2Favailable_later%3E%0A%3Cassociations%3E%0A%3Ccategories%3E%0A%09%3Ccategory%3E%0A%09%3Cid+%2F%3E%0A%09%3C%2Fcategory%3E%0A%3C%2Fcategories%3E%0A%3Cimages%3E%0A%09%3Cimage%3E%0A%09%3Cid+%2F%3E%0A%09%3C%2Fimage%3E%0A%3C%2Fimages%3E%0A%3Ccombinations%3E%0A%09%3Ccombinations%3E%0A%09%3Cid+%2F%3E%0A%09%3C%2Fcombinations%3E%0A%3C%2Fcombinations%3E%0A%3Cproduct_option_values%3E%0A%09%3Cproduct_options_values%3E%0A%09%3Cid+%2F%3E%0A%09%3C%2Fproduct_options_values%3E%0A%3C%2Fproduct_option_values%3E%0A%3Cproduct_features%3E%0A%09%3Cproduct_feature%3E%0A%09%3Cid+%2F%3E%0A%09%3Ccustom+%2F%3E%0A%09%3Cid_feature_value+%2F%3E%0A%09%3C%2Fproduct_feature%3E%0A%3C%2Fproduct_features%3E%0A%3Ctags%3E%0A%09%3Ctag%3E%0A%09%3Cid+%2F%3E%0A%09%3C%2Ftag%3E%0A%3C%2Ftags%3E%0A%3Cstock_availables%3E%0A%09%3Cstock_available%3E%0A%09%3Cid+%2F%3E%0A%09%3Cid_product_attribute+%2F%3E%0A%09%3C%2Fstock_available%3E%0A%3C%2Fstock_availables%3E%0A%3Caccessories%3E%0A%09%3Cproduct%3E%0A%09%3Cid+%2F%3E%0A%09%3C%2Fproduct%3E%0A%3C%2Faccessories%3E%0A%3Cproduct_bundle%3E%0A%09%3Cproducts%3E%0A%09%3Cid+%2F%3E%0A%09%3Cquantity+%2F%3E%0A%09%3C%2Fproducts%3E%0A%3C%2Fproduct_bundle%3E%0A%3C%2Fassociations%3E%0A%3C%2Fproduct%3E%0A%3C%2Fprestashop%3E]]></message>\n</error>\n</errors>\n</prestashop>\n''

它可以解析XML。为什么Prestashop不能?

如果您仍在搜索解决方案: 我认为问题在于prestashop不再以URL编码的方式获取数据。因此,只需发布xml就可以了

$xml = simplexml_load_string($_REQUEST['XML']);
var_dump($xml);[/code]