dplase3140 2014-06-11 09:59
浏览 66
已采纳

将产品通过REST添加到PrestaShop时出现XML解析器错误

I am trying to create simple GUI in Python3 to adding product to shop. This is a part of code:

 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

Unfortunately I always get this answer:

`<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<errors>
<error>
<code><![CDATA[127]]></code>
<message><![CDATA[XML error : String could not be parsed as XML
XML length : 3379
Original 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>
</error>
</errors>
</prestashop>
''

I'm trying to fix this for a couple of days. Please help me what I did wrong?

I made a simple php script to my app:

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

and it can parse a XML. Why Prestashop cannot?

  • 写回答

1条回答 默认 最新

  • doupingtang9627 2015-04-15 17:43
    关注

    In case you are still searching for a solution: I think the problem is that prestashop no longer gets the data as urlencoded. So just posting the xml will work

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,