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

Fixed an exception with an empty response #58

Merged
merged 2 commits into from
Apr 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ In order to use eBay aspects of this utility you must first register with eBay t

Example::

from ebaysdk import finding, tag, nodeText
from ebaysdk import getNodeText
from ebaysdk.finding import Connection as finding

f = finding()
f.execute('findItemsAdvanced', tag('keywords', 'shoes'))
f.execute('findItemsAdvanced', {'keywords': 'shoes'})

dom = f.response_dom()
mydict = f.response_dict()
Expand All @@ -22,7 +23,7 @@ Example::
items = dom.getElementsByTagName('item')

for item in items:
print nodeText(item.getElementsByTagName('title')[0])
print getNodeText(item.getElementsByTagName('title')[0])

.. _eBay Developer Site: http://developer.ebay.com/

53 changes: 38 additions & 15 deletions ebaysdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_version():

def set_file_logger(name, filepath, level=logging.INFO, format_string=None):
global log
log.handlers=[]
log.handlers = []

if not format_string:
format_string = "%(asctime)s %(name)s [%(levelname)s]:%(message)s"
Expand All @@ -51,7 +51,7 @@ def set_file_logger(name, filepath, level=logging.INFO, format_string=None):

def set_stream_logger(name, level=logging.DEBUG, format_string=None):
global log
log.handlers=[]
log.handlers = []

if not format_string:
format_string = "%(asctime)s %(name)s [%(levelname)s]:%(message)s"
Expand All @@ -65,26 +65,49 @@ def set_stream_logger(name, level=logging.DEBUG, format_string=None):
log = logger

def trading(*args, **kwargs):
from ebaysdk.trading import Connection as Trading
return Trading(*args, **kwargs)
raise ImportError(
'SDK import must be changed as follows:\n\n- %s\n+ %s\n\n' % (
'from ebaysdk import trading',
'from ebaysdk.trading import Connection as trading',
)
)

def shopping(*args, **kwargs):
from ebaysdk.shopping import Connection as Shopping
return Shopping(*args, **kwargs)
raise ImportError(
'SDK import must be changed as follows:\n\n- %s\n+ %s\n\n' % (
'from ebaysdk import shopping',
'from ebaysdk.shopping import Connection as shopping',
)
)

def finding(*args, **kwargs):
from ebaysdk.finding import Connection as Finding
return Finding(*args, **kwargs)
raise ImportError(
'SDK import must be changed as follows:\n\n- %s\n+ %s\n\n' % (
'from ebaysdk import finding',
'from ebaysdk.finding import Connection as finding',
)
)

def merchandising(*args, **kwargs):
from ebaysdk.merchandising import Connection as Merchandising
return Merchandising(*args, **kwargs)
raise ImportError(
'SDK import must be changed as follows:\n\n- %s\n+ %s\n\n' % (
'from ebaysdk import merchandising',
'from ebaysdk.merchandising import Connection as merchandising',
)
)

def html(*args, **kwargs):
from ebaysdk.http import Connection as HTTP
return HTTP(*args, **kwargs)
raise ImportError(
'SDK import must be changed as follows:\n\n- %s\n+ %s\n\n' % (
'from ebaysdk import html',
'from ebaysdk.http import Connection as html',
)
)

def parallel(*args, **kwargs):
from ebaysdk.parallel import Parallel
return Parallel(*args, **kwargs)

raise ImportError(
'SDK import must be changed as follows:\n\n- %s\n+ %s\n\n' % (
'from ebaysdk import parallel',
'from ebaysdk.parallel import Parallel as parallel',
)
)
2 changes: 1 addition & 1 deletion ebaysdk/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Parallel(object):
"""
>>> from ebaysdk.finding import Connection as finding
>>> from ebaysdk.shopping import Connection as shopping
>>> from ebaysdk import html
>>> from ebaysdk.http import Connection as html
>>> import os
>>> p = Parallel()
>>> r1 = html(parallel=p)
Expand Down
15 changes: 8 additions & 7 deletions ebaysdk/soa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@ def response_dict(self):
if self._response_dict:
return self._response_dict

mydict = xml2dict().fromstring(self._response_content)

try:
verb = self.verb + 'Response'
self._response_dict = mydict['Envelope']['Body'][verb]
if self._response_content:
mydict = xml2dict().fromstring(self._response_content)

try:
verb = self.verb + 'Response'
self._response_dict = mydict['Envelope']['Body'][verb]

except KeyError:
self._response_dict = mydict.get(self.verb + 'Response', mydict)
except KeyError:
self._response_dict = mydict.get(self.verb + 'Response', mydict)

return self._response_dict

Expand Down
2 changes: 1 addition & 1 deletion samples/merchandising.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from common import dump

import ebaysdk
from ebaysdk import merchandising
from ebaysdk.merchandising import Connection as merchandising
from ebaysdk.exception import ConnectionError

def init_options():
Expand Down
3 changes: 2 additions & 1 deletion samples/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
sys.path.insert(0, '%s/../' % os.path.dirname(__file__))

from common import dump
from ebaysdk import finding, html
from ebaysdk.finding import Connection as finding
from ebaysdk.http import Connection as html
from ebaysdk.parallel import Parallel
from ebaysdk.exception import ConnectionError

Expand Down