Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION] Send xml file #361

Open
viandanteoscuro opened this issue Jul 22, 2021 · 1 comment
Open

[QUESTION] Send xml file #361

viandanteoscuro opened this issue Jul 22, 2021 · 1 comment

Comments

@viandanteoscuro
Copy link

viandanteoscuro commented Jul 22, 2021

Hi,

Can i send directly an xml string instead of a dict data?

I tried to pass an xml for an AddFixedPriceItem but a have an error...

The xml:

<AddFixedPriceItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">
<Item xmlns="urn:ebay:apis:eBLBaseComponents">
 <Country>IT</Country>
 <Currency>EUR</Currency>
<ListingDuration>GTC</ListingDuration>
...

but i got this error:

AddFixedPriceItem: Class: RequestError, Severity: Error, Code: 10009, No <Item.Currency> exists or <Item.Currency> is specified as an empty tag. No <Item.Currency> exists or <Item.Currency> is specified as an empty tag in the request., Class: RequestError, Severity: Error, Code: 10009, No <Item.Country> exists or <Item.Country> is specified as an empty tag. No <Item.Country> exists or <Item.Country> is specified as an empty tag in the request., Class: RequestError, Severity: Error, Code: 10009, No <Item.ListingDuration> exists or <Item.ListingDuration> is specified as an empty tag. No <Item.ListingDuration> exists or <Item.ListingDuration> is specified as an empty tag in the request.

Is it possible to send plain xml?

Or i must convert it to dict?

Thanks!

Massimo

@mmcc-xx
Copy link

mmcc-xx commented Sep 22, 2021

I have the same question - I'm building an AddItem request in XML and converting it to a dict, but that conversion isn't working properly. There is a file input to the execute method - can that be used for an xml file?

Update:
I dug into the code a little bit and it would seem that no, an xml file can not be passed with the file argument.

Here's my kludegy workaround that seems to be working correctly.

I'm using a library called xmltodict.
The json library is also needed. This is because xmltodict outputs an OrderedDict and we need a normal dict, and the way I found of converting a nested OrderedDict to a Dict involves doing a json dump and load. Anyway...

say we have a string requestxml containing the following:

<GetCategorySpecificsRequest>
  <WarningLevel>High</WarningLevel>
  <CategorySpecific>
    <CategoryID>176985</CategoryID>
  </CategorySpecific>
</GetCategorySpecificsRequest>

I use the following to convert the xml to an OrderedDict, then a dict, and then do the request.

request = xmltodict.parse(requestxml)
request = json.loads(json.dumps(request))
response = api.execute('GetCategorySpecifics', request['GetCategorySpecificsRequest'])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants