diff --git a/.gitignore b/.gitignore index 0a764d8..74036df 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ ebaysdk.egg-info/ \.DS_Store \.eggs \.tox -venv/ -venv* +.venv/ +.venv* \.virtualenvs + diff --git a/Changes b/Changes index 699ad0c..0517a87 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,16 @@ Changes for ebaysdk +2.2.0 Mon Apr 20 15:23:53 PDT 2020 +- Forced HTTPS for finding, shopping, and trading calls +- fixed sample code so that it uses the appropriate domain +- added py38 to tox testing + +2.1.6 +- Update Copyright + +2.1.5 Oct 13, 2017 +- Bug fix release + 2.1.4 Tue Aug 23 11:21:37 PDT 2016 - Merge PR from listingmirror for site-id fix - Added a few performance tests diff --git a/INSTALL b/INSTALL index 48975dd..2e4a930 100644 --- a/INSTALL +++ b/INSTALL @@ -11,9 +11,10 @@ Installing ebaysdk on Mac, Linux, Unix: Ubuntu: sudo apt-get install python-lxml -2) Install the SDK with easy_install +2) Install the SDK with pip - sudo easy_install ebaysdk + python3 -m pip install ebaysdk + Or install the latest version from github, diff --git a/ebay.yaml b/ebay.yaml index fc170b6..2ab6ed3 100644 --- a/ebay.yaml +++ b/ebay.yaml @@ -19,9 +19,7 @@ api.ebay.com: # Finding API - https://www.x.com/developers/ebay/products/finding-api svcs.ebay.com: appid: ENTER_YOUR_APPID_HERE - version: 1.0.0 # Shopping API - https://www.x.com/developers/ebay/products/shopping-api open.api.ebay.com: appid: ENTER_YOUR_APPID_HERE - version: 671 diff --git a/ebaysdk/__init__.py b/ebaysdk/__init__.py index 79b6c1a..5630928 100644 --- a/ebaysdk/__init__.py +++ b/ebaysdk/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' @@ -9,7 +9,7 @@ import platform import logging -__version__ = '2.1.5' +__version__ = '2.2.0' Version = __version__ # for backward compatibility try: diff --git a/ebaysdk/config.py b/ebaysdk/config.py index ed857af..fb697ef 100644 --- a/ebaysdk/config.py +++ b/ebaysdk/config.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' diff --git a/ebaysdk/connection.py b/ebaysdk/connection.py index 77d5f8f..a29a644 100644 --- a/ebaysdk/connection.py +++ b/ebaysdk/connection.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' @@ -149,7 +149,7 @@ def build_request(self, verb, data, verb_attrs, files=None): requestData = self.build_request_data(verb, data, verb_attrs) if files: del(headers['Content-Type']) - if isinstance(requestData, basestring): # pylint: disable-msg=E0602 + if isinstance(requestData, str): # pylint: disable-msg=E0602 requestData = {'XMLPayload': requestData} request = Request(self.method, @@ -169,7 +169,7 @@ def build_request_data(self, verb, data, verb_attrs): def build_request_url(self, verb): url = "%s://%s%s" % ( - HTTP_SSL[self.config.get('https', False)], + HTTP_SSL[self.config.get('https', True)], self.config.get('domain'), self.config.get('uri') ) @@ -208,6 +208,7 @@ def process_response(self, parse_response=True): datetime_nodes=self.datetime_nodes, parse_response=parse_response) + self.session.close() # set for backward compatibility self._response_content = self.response.content @@ -245,7 +246,7 @@ def response_soup(self): from bs4 import BeautifulStoneSoup except ImportError: from BeautifulSoup import BeautifulStoneSoup - log.warn( + log.warning( 'DeprecationWarning: BeautifulSoup 3 or earlier is deprecated; install bs4 instead\n') self._response_soup = BeautifulStoneSoup( @@ -255,14 +256,14 @@ def response_soup(self): return self._response_soup def response_obj(self): - log.warn('response_obj() DEPRECATED, use response.reply instead') + log.warning('response_obj() DEPRECATED, use response.reply instead') return self.response.reply def response_dom(self): """ Deprecated: use self.response.dom() instead Returns the response DOM (xml.dom.minidom). """ - log.warn('response_dom() DEPRECATED, use response.dom instead') + log.warning('response_dom() DEPRECATED, use response.dom instead') if not self._response_dom: dom = None @@ -290,14 +291,14 @@ def response_dom(self): def response_dict(self): "Returns the response dictionary." - log.warn( + log.warning( 'response_dict() DEPRECATED, use response.dict() or response.reply instead') return self.response.reply def response_json(self): "Returns the response JSON." - log.warn('response_json() DEPRECATED, use response.json() instead') + log.warning('response_json() DEPRECATED, use response.json() instead') return self.response.json() diff --git a/ebaysdk/exception.py b/ebaysdk/exception.py index 27355a3..572cf7c 100644 --- a/ebaysdk/exception.py +++ b/ebaysdk/exception.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' diff --git a/ebaysdk/finding/__init__.py b/ebaysdk/finding/__init__.py index 34dd83e..64a9286 100644 --- a/ebaysdk/finding/__init__.py +++ b/ebaysdk/finding/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' @@ -28,7 +28,7 @@ class Connection(BaseConnection): Doctests: >>> f = Connection(config_file=os.environ.get('EBAY_YAML'), debug=False) - >>> retval = f.execute('findItemsAdvanced', {'keywords': u'niño'}) + >>> retval = f.execute('findItemsAdvanced', {'keywords': u'El Niño'}) >>> error = f.error() >>> print(error) None @@ -55,7 +55,7 @@ def __init__(self, **kwargs): appid -- eBay application id siteid -- eBay country site id (default: EBAY-US) version -- version number (default: 1.0.0) - https -- execute of https (default: False) + https -- execute of https (default: True) proxy_host -- proxy hostname proxy_port -- proxy port number timeout -- HTTP request timeout (default: 20) @@ -73,7 +73,7 @@ def __init__(self, **kwargs): # override yaml defaults with args sent to the constructor self.config.set('domain', kwargs.get('domain', 'svcs.ebay.com')) self.config.set('uri', '/services/search/FindingService/v1') - self.config.set('https', False) + self.config.set('https', True, force=True) self.config.set('warnings', True) self.config.set('errors', True) self.config.set('siteid', 'EBAY-US') @@ -270,7 +270,7 @@ def _get_resp_body_errors(self): self._resp_codes = resp_codes if self.config.get('warnings') and len(warnings) > 0: - log.warn("%s: %s\n\n" % (self.verb, "\n".join(warnings))) + log.warning("%s: %s\n\n" % (self.verb, "\n".join(warnings))) try: if self.response.reply.ack == 'Success' and len(errors) > 0 and self.config.get('errors'): diff --git a/ebaysdk/http/__init__.py b/ebaysdk/http/__init__.py index 8200757..f4c62b1 100644 --- a/ebaysdk/http/__init__.py +++ b/ebaysdk/http/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' diff --git a/ebaysdk/inventorymanagement/__init__.py b/ebaysdk/inventorymanagement/__init__.py index c9ee40a..f1bf98c 100644 --- a/ebaysdk/inventorymanagement/__init__.py +++ b/ebaysdk/inventorymanagement/__init__.py @@ -296,7 +296,7 @@ def _get_resp_body_errors(self): self._resp_codes = resp_codes if self.config.get('warnings') and len(warnings) > 0: - log.warn("{verb}: {message}\n\n".format( + log.warning("{verb}: {message}\n\n".format( verb=self.verb, message="\n".join(warnings))) # In special case of error 500 on ebay side, we get really weird diff --git a/ebaysdk/merchandising/__init__.py b/ebaysdk/merchandising/__init__.py index 74fd60e..b84a039 100644 --- a/ebaysdk/merchandising/__init__.py +++ b/ebaysdk/merchandising/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' diff --git a/ebaysdk/parallel.py b/ebaysdk/parallel.py index e40c769..0320c97 100644 --- a/ebaysdk/parallel.py +++ b/ebaysdk/parallel.py @@ -1,16 +1,16 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' -import sys + from ebaysdk.exception import ConnectionError -import grequests -if sys.version_info[0] >= 3: - raise ImportError('grequests does not work with python3+') +# pylint: disable=import-error +import grequests +# pylint: enable=import-error class Parallel(object): diff --git a/ebaysdk/policies/__init__.py b/ebaysdk/policies/__init__.py index 51e1b4d..278cfdf 100644 --- a/ebaysdk/policies/__init__.py +++ b/ebaysdk/policies/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' @@ -208,7 +208,7 @@ def _get_resp_body_errors(self): self._resp_codes = resp_codes if self.config.get('warnings') and len(warnings) > 0: - log.warn("%s: %s\n\n" % (self.verb, "\n".join(warnings))) + log.warning("%s: %s\n\n" % (self.verb, "\n".join(warnings))) try: if self.response.reply.ack == 'Success' and len(errors) > 0 and self.config.get('errors'): diff --git a/ebaysdk/poller/__init__.py b/ebaysdk/poller/__init__.py index 14afee3..0551d7a 100644 --- a/ebaysdk/poller/__init__.py +++ b/ebaysdk/poller/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ''' -© 2012-2015 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' diff --git a/ebaysdk/poller/orders.py b/ebaysdk/poller/orders.py index afa663f..0241d4c 100644 --- a/ebaysdk/poller/orders.py +++ b/ebaysdk/poller/orders.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- ''' +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' diff --git a/ebaysdk/response.py b/ebaysdk/response.py index 79afa2b..fca9a0d 100644 --- a/ebaysdk/response.py +++ b/ebaysdk/response.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' @@ -161,7 +161,10 @@ def __init__(self, obj, verb=None, list_nodes=[], datetime_nodes=[], parse_respo datetime_nodes=copy.copy(datetime_nodes)) except XMLSyntaxError as e: log.debug('response parse failed: %s' % e) + self._dom = self._parse_xml("<%sResponse>parse error " % (verb, e, verb)) + self._dict = self._etree_to_dict(self._dom) self.reply = ResponseDataObject({}, []) + else: self.reply = ResponseDataObject({}, []) diff --git a/ebaysdk/shopping/__init__.py b/ebaysdk/shopping/__init__.py index a34b92e..bb01854 100644 --- a/ebaysdk/shopping/__init__.py +++ b/ebaysdk/shopping/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' @@ -72,28 +72,27 @@ def __init__(self, **kwargs): self.config.set('uri', '/shopping') self.config.set('warnings', True) self.config.set('errors', True) - self.config.set('https', False) + self.config.set('https', True, force=True) self.config.set('siteid', '0') self.config.set('response_encoding', 'XML') self.config.set('request_encoding', 'XML') self.config.set('proxy_host', None) self.config.set('proxy_port', None) self.config.set('appid', None) + self.config.set('iaf_token', None) self.config.set('version', '799') self.config.set('trackingid', None) self.config.set('trackingpartnercode', None) self.config.set( 'doc_url', 'http://developer.ebay.com/DevZone/Shopping/docs/CallRef/index.html') - if self.config.get('https') and self.debug: - print("HTTPS is not supported on the Shopping API.") - self.datetime_nodes = ['timestamp', 'registrationdate', 'creationtime', 'commenttime', 'updatetime', 'estimateddeliverymintime', 'estimateddeliverymaxtime', 'creationtime', 'estimateddeliverymintime', 'estimateddeliverymaxtime', 'endtime', 'starttime'] self.base_list_nodes = [ + 'getcategoryinforesponse.categoryarray.category', 'findhalfproductsresponse.halfcatalogproduct.productid', 'findhalfproductsresponse.halfproducts.product', 'getshippingcostsresponse.internationalshippingserviceoption.shipsto', @@ -148,6 +147,10 @@ def build_request_headers(self, verb): "X-EBAY-API-TRACKING-PARTNER-CODE": self.config.get('trackingpartnercode') }) + if self.config.get('iaf_token', None): + headers["X-EBAY-API-IAF-TOKEN"] = self.config.get('iaf_token') + + return headers def build_request_data(self, verb, data, verb_attrs): @@ -246,7 +249,7 @@ def _get_resp_body_errors(self): self._resp_codes = resp_codes if self.config.get('warnings') and len(warnings) > 0: - log.warn("%s: %s\n\n" % (self.verb, "\n".join(warnings))) + log.warning("%s: %s\n\n" % (self.verb, "\n".join(warnings))) if self.response.reply.Ack == 'Failure': if self.config.get('errors'): diff --git a/ebaysdk/soa/__init__.py b/ebaysdk/soa/__init__.py index 67f003b..f3d80f2 100644 --- a/ebaysdk/soa/__init__.py +++ b/ebaysdk/soa/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' @@ -178,7 +178,7 @@ def _get_resp_body_errors(self): self._resp_codes = resp_codes if self.config.get('warnings') and len(warnings) > 0: - log.warn("%s: %s\n\n" % (self.verb, "\n".join(warnings))) + log.warning("%s: %s\n\n" % (self.verb, "\n".join(warnings))) try: if self.response.reply.ack == 'Success' and len(errors) > 0 and self.config.get('errors'): diff --git a/ebaysdk/soa/finditem.py b/ebaysdk/soa/finditem.py index d70e91e..dd533d6 100644 --- a/ebaysdk/soa/finditem.py +++ b/ebaysdk/soa/finditem.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' diff --git a/ebaysdk/trading/__init__.py b/ebaysdk/trading/__init__.py index 1349c19..7918417 100644 --- a/ebaysdk/trading/__init__.py +++ b/ebaysdk/trading/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' @@ -87,7 +87,7 @@ def __init__(self, **kwargs): self.config.set('uri', '/ws/api.dll') self.config.set('warnings', True) self.config.set('errors', True) - self.config.set('https', True) + self.config.set('https', True, force=True) self.config.set('siteid', '0') self.config.set('response_encoding', 'XML') self.config.set('request_encoding', 'XML') @@ -217,6 +217,7 @@ def __init__(self, **kwargs): 'getmembermessagesresponse.abstractrequest.outputselector', 'getmyebaybuyingresponse.abstractrequest.outputselector', 'getmyebaysellingresponse.abstractrequest.outputselector', + 'getmyebaysellingresponse.activelist.itemarray.item', 'getmymessagesresponse.abstractrequest.outputselector', 'getnotificationpreferencesresponse.abstractrequest.outputselector', 'getordersresponse.abstractrequest.outputselector', @@ -797,7 +798,7 @@ def _get_resp_body_errors(self): self._resp_codes = resp_codes if self.config.get('warnings') and len(warnings) > 0: - log.warn("{verb}: {message}\n\n".format( + log.warning("{verb}: {message}\n\n".format( verb=self.verb, message="\n".join(warnings))) if self.response.reply.Ack == 'Failure': diff --git a/ebaysdk/utils.py b/ebaysdk/utils.py index 64ac996..ff819e2 100644 --- a/ebaysdk/utils.py +++ b/ebaysdk/utils.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' @@ -97,9 +97,12 @@ def smart_encode_request_data(value): if sys.version_info[0] < 3: return value - return value.encode('utf-8') + if isinstance(value, str): + return value.encode('utf-8') + else: + return value - except UnicodeDecodeError: + except UnicodeDecodeError as e: return value @@ -295,7 +298,7 @@ def getValue(response_dict, *args, **kwargs): if len(args) == 1: try: return h.get('value', None) - except: + except Exception as e: return h last = args_a.pop() @@ -307,7 +310,7 @@ def getValue(response_dict, *args, **kwargs): try: return h.get('value', None) - except: + except Exception as e: return h @@ -344,6 +347,7 @@ def perftest_dict2xml(): xml = dict2xml(sample_dict) + if __name__ == '__main__': import timeit diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index a3596c0..0000000 --- a/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -lxml -requests diff --git a/samples/calls_with_unicode.py b/samples/calls_with_unicode.py index 26ea1a2..1f68bce 100644 --- a/samples/calls_with_unicode.py +++ b/samples/calls_with_unicode.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' @@ -30,7 +30,9 @@ def init_options(): parser.add_option("-a", "--appid", dest="appid", default=None, help="Specifies the eBay application id to use.") - + parser.add_option("-n", "--domain", + dest="domain", default='svcs.ebay.com', + help="Specifies the eBay domain to use (e.g. svcs.sandbox.ebay.com).") (opts, args) = parser.parse_args() return opts, args @@ -38,7 +40,7 @@ def init_options(): def run(opts): try: - api = finding(debug=opts.debug, appid=opts.appid, + api = finding(debug=opts.debug, appid=opts.appid, domain=opts.domain, config_file=opts.yaml, warnings=True) api_request = { @@ -65,7 +67,7 @@ def run(opts): def run_unicode(opts): try: - api = finding(debug=opts.debug, appid=opts.appid, + api = finding(debug=opts.debug, appid=opts.appid, domain=opts.domain, config_file=opts.yaml, warnings=True) api_request = { @@ -83,7 +85,7 @@ def run_unicode(opts): except ConnectionError as e: print(e) print(e.response.dict()) - + if __name__ == "__main__": print("Unicode samples for SDK version %s" % ebaysdk.get_version()) (opts, args) = init_options() diff --git a/samples/common.py b/samples/common.py index 67aa047..6271b3a 100644 --- a/samples/common.py +++ b/samples/common.py @@ -1,10 +1,23 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' +from ebaysdk.finding import Connection as finding + +def get_one_item(opts): + api = finding(debug=opts.debug, appid=opts.appid, + config_file=opts.yaml, warnings=True) + + api_request = { + 'keywords': u'GRAMMY Foundation®', + } + + response = api.execute('findItemsAdvanced', api_request) + return response.reply.searchResult.item[0].itemId + def dump(api, full=False): @@ -17,7 +30,7 @@ def dump(api, full=False): print("Call Success: %s in length" % len(api.response.content)) print("Response code: %s" % api.response_code()) - print("Response DOM1: %s" % api.response_dom()) # deprecated + print("Response DOM1: %s" % api.response.dom()) # deprecated print("Response ETREE: %s" % api.response.dom()) if full: diff --git a/samples/finding.py b/samples/finding.py index bb45bf5..00d8a0e 100644 --- a/samples/finding.py +++ b/samples/finding.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' diff --git a/samples/finditem.py b/samples/finditem.py index 492b01d..e989b4f 100644 --- a/samples/finditem.py +++ b/samples/finditem.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' @@ -36,6 +36,9 @@ def init_options(): parser.add_option("-c", "--consumer_id", dest="consumer_id", default=None, help="Specifies the eBay consumer_id id to use.") + parser.add_option("-n", "--domain", + dest="domain", default='svcs.ebay.com', + help="Specifies the eBay domain to use (e.g. svcs.sandbox.ebay.com).") (opts, args) = parser.parse_args() return opts, args @@ -45,7 +48,7 @@ def run(opts): try: - shopping = Shopping(debug=opts.debug, appid=opts.appid, + shopping = Shopping(debug=opts.debug, appid=opts.appid, domain=opts.domain, config_file=opts.yaml, warnings=False) response = shopping.execute('FindPopularItems', diff --git a/samples/merchandising.py b/samples/merchandising.py index a6d090c..8326ed7 100644 --- a/samples/merchandising.py +++ b/samples/merchandising.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' @@ -30,6 +30,9 @@ def init_options(): parser.add_option("-a", "--appid", dest="appid", default=None, help="Specifies the eBay application id to use.") + parser.add_option("-n", "--domain", + dest="domain", default='svcs.ebay.com', + help="Specifies the eBay domain to use (e.g. svcs.sandbox.ebay.com).") (opts, args) = parser.parse_args() return opts, args @@ -37,7 +40,7 @@ def init_options(): def run(opts): try: - api = merchandising(debug=opts.debug, appid=opts.appid, + api = merchandising(debug=opts.debug, appid=opts.appid, domain=opts.domain, config_file=opts.yaml, warnings=True) response = api.execute('getMostWatchedItems', {'maxResults': 4}) diff --git a/samples/parallel.py b/samples/parallel.py index 45a55ca..5e4c1bd 100644 --- a/samples/parallel.py +++ b/samples/parallel.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' @@ -31,7 +31,9 @@ def init_options(): parser.add_option("-a", "--appid", dest="appid", default=None, help="Specifies the eBay application id to use.") - + parser.add_option("-n", "--domain", + dest="domain", default='svcs.ebay.com', + help="Specifies the eBay domain to use (e.g. svcs.sandbox.ebay.com).") (opts, args) = parser.parse_args() return opts, args @@ -42,7 +44,7 @@ def run(opts): p = Parallel() apis = [] - api1 = finding(parallel=p, debug=opts.debug, + api1 = finding(parallel=p, debug=opts.debug, domain=opts.domain, appid=opts.appid, config_file=opts.yaml) api1.execute('findItemsAdvanced', {'keywords': 'python'}) apis.append(api1) @@ -51,12 +53,12 @@ def run(opts): api4.execute('http://www.ebay.com/sch/i.html?_nkw=Shirt&_rss=1') apis.append(api4) - api2 = finding(parallel=p, debug=opts.debug, + api2 = finding(parallel=p, debug=opts.debug, domain=opts.domain, appid=opts.appid, config_file=opts.yaml) api2.execute('findItemsAdvanced', {'keywords': 'perl'}) apis.append(api2) - api3 = finding(parallel=p, debug=opts.debug, + api3 = finding(parallel=p, debug=opts.debug, domain=opts.domain, appid=opts.appid, config_file=opts.yaml) api3.execute('findItemsAdvanced', {'keywords': 'php'}) apis.append(api3) diff --git a/samples/parallel_gevent.py b/samples/parallel_gevent.py index 1a5b760..f0823a4 100644 --- a/samples/parallel_gevent.py +++ b/samples/parallel_gevent.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' @@ -32,6 +32,9 @@ def init_options(): parser.add_option("-a", "--appid", dest="appid", default=None, help="Specifies the eBay application id to use.") + parser.add_option("-n", "--domain", + dest="domain", default='svcs.ebay.com', + help="Specifies the eBay domain to use (e.g. svcs.sandbox.ebay.com).") (opts, args) = parser.parse_args() return opts, args @@ -46,7 +49,7 @@ def run(opts): calls = [] for page in range(1, 10): - api = finding(debug=opts.debug, appid=opts.appid, + api = finding(debug=opts.debug, appid=opts.appid, domain=opts.domain, config_file=opts.yaml) call = gevent.spawn(api.execute, 'findItemsAdvanced', diff --git a/samples/policies.py b/samples/policies.py index 696a0c6..7d9ca38 100644 --- a/samples/policies.py +++ b/samples/policies.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' @@ -39,6 +39,9 @@ def init_options(): parser.add_option("-c", "--certid", dest="certid", default=None, help="Specifies the eBay cert id to use.") + parser.add_option("-n", "--domain", + dest="domain", default='svcs.ebay.com', + help="Specifies the eBay domain to use (e.g. svcs.sandbox.ebay.com).") (opts, args) = parser.parse_args() return opts, args @@ -46,7 +49,7 @@ def init_options(): def getSellerProfiles(opts): try: - api = Policies(debug=opts.debug, config_file=opts.yaml, appid=opts.appid, + api = Policies(debug=opts.debug, config_file=opts.yaml, appid=opts.appid, domain=opts.domain, certid=opts.certid, devid=opts.devid) api.execute('getSellerProfiles') @@ -59,7 +62,7 @@ def getSellerProfiles(opts): def getConsolidationJobStatus(opts): try: - api = Policies(debug=opts.debug, config_file=opts.yaml, appid=opts.appid, + api = Policies(debug=opts.debug, config_file=opts.yaml, appid=opts.appid, domain=opts.domain, certid=opts.certid, devid=opts.devid) api.execute('getConsolidationJobStatus') diff --git a/samples/poller.py b/samples/poller.py index 87e995f..0364c9c 100644 --- a/samples/poller.py +++ b/samples/poller.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' diff --git a/samples/request_dictionary.py b/samples/request_dictionary.py index 75a0133..3c6f740 100644 --- a/samples/request_dictionary.py +++ b/samples/request_dictionary.py @@ -1,3 +1,9 @@ +# -*- coding: utf-8 -*- +''' +Copyright 2012-2019 eBay Inc. +Authored by: Tim Keefer +Licensed under CDDL 1.0 +''' import os import sys diff --git a/samples/shopping.py b/samples/shopping.py index 703409b..34ff558 100644 --- a/samples/shopping.py +++ b/samples/shopping.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' @@ -16,7 +16,7 @@ sys.path.insert(0, '%s/../' % os.path.dirname(__file__)) -from common import dump +from common import dump, get_one_item import ebaysdk from ebaysdk.exception import ConnectionError @@ -36,25 +36,27 @@ def init_options(): parser.add_option("-a", "--appid", dest="appid", default=None, help="Specifies the eBay application id to use.") + parser.add_option("-n", "--domain", + dest="domain", default='open.api.ebay.com', + help="Specifies the eBay domain to use (e.g. open.api.ebay.com).") (opts, args) = parser.parse_args() return opts, args def run(opts): - api = Shopping(debug=opts.debug, appid=opts.appid, config_file=opts.yaml, + api = Shopping(debug=opts.debug, appid=opts.appid, config_file=opts.yaml, domain=opts.domain, warnings=True) print("Shopping samples for SDK version %s" % ebaysdk.get_version()) try: - response = api.execute('FindPopularItems', {'QueryKeywords': 'Python'}) + ItemID = get_one_item(opts) - dump(api) + response = api.execute('GetSingleItem', {'ItemID': ItemID}) + print("EndTime: %s" % response.reply.Item.EndTime) - print("Matching Titles:") - for item in response.reply.ItemArray.Item: - print(item.Title) + dump(api) except ConnectionError as e: print(e) @@ -63,80 +65,39 @@ def run(opts): def popularSearches(opts): - api = Shopping(debug=opts.debug, appid=opts.appid, config_file=opts.yaml, + api = Shopping(debug=opts.debug, appid=opts.appid, config_file=opts.yaml, domain=opts.domain, warnings=True) - choice = True - - while choice: - - choice = input('Search: ') - - if choice == 'quit': - break - - mySearch = { - "MaxKeywords": 10, - "QueryKeywords": choice, - } - - try: - response = api.execute('FindPopularSearches', mySearch) - - dump(api, full=False) - - print("Related: %s" % - response.reply.PopularSearchResult.RelatedSearches) - - for term in response.reply.PopularSearchResult.AlternativeSearches.split(';')[:3]: - api.execute('FindPopularItems', { - 'QueryKeywords': term, 'MaxEntries': 3}) - - print("Term: %s" % term) - - try: - for item in response.reply.ItemArray.Item: - print(item.Title) - except AttributeError: - pass - - dump(api) - - print("\n") - - except ConnectionError as e: - print(e) - print(e.response.dict()) - - -def categoryInfo(opts): + mySearch = { + "MaxKeywords": 10, + "QueryKeywords": 'shirt', + } try: - api = Shopping(debug=opts.debug, appid=opts.appid, config_file=opts.yaml, - warnings=True) - - response = api.execute('GetCategoryInfo', {"CategoryID": 3410}) + response = api.execute('FindPopularSearches', mySearch) dump(api, full=False) + print("Related: %s" % + response.reply.PopularSearchResult.RelatedSearches) + except ConnectionError as e: print(e) print(e.response.dict()) -def with_affiliate_info(opts): +def categoryInfo(opts): + try: - api = Shopping(debug=opts.debug, appid=opts.appid, - config_file=opts.yaml, warnings=True, - trackingid=1234, trackingpartnercode=9) + api = Shopping(debug=opts.debug, appid=opts.appid, config_file=opts.yaml, domain=opts.domain, + warnings=True) - mySearch = { - "MaxKeywords": 10, - "QueryKeywords": 'shirt', - } + response = api.execute('GetCategoryInfo', {"CategoryID": 11450}) - response = api.execute('FindPopularSearches', mySearch) - dump(api, full=False) + print("Category Name: %s" % + response.reply.CategoryArray.Category[0].CategoryName) + + dump(api) except ConnectionError as e: print(e) @@ -164,5 +125,4 @@ def using_attributes(opts): run(opts) popularSearches(opts) categoryInfo(opts) - with_affiliate_info(opts) using_attributes(opts) diff --git a/samples/storeMeta.py b/samples/storeMeta.py index 9098e53..74e73e5 100644 --- a/samples/storeMeta.py +++ b/samples/storeMeta.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' @@ -46,6 +46,9 @@ def init_options(): parser.add_option("-e", "--line_end", dest="line_end", default=None, help="Input file lines.") + parser.add_option("-n", "--domain", + dest="domain", default='svcs.ebay.com', + help="Specifies the eBay domain to use (e.g. svcs.sandbox.ebay.com).") (opts, args) = parser.parse_args() return opts, args @@ -129,7 +132,7 @@ def get_store_meta(store_name): try: api = finding(debug=opts.debug, appid=opts.appid, - config_file=opts.yaml) + config_file=opts.yaml, domain=opts.domain) response = api.execute('findItemsIneBayStores', { 'storeName': store_name, @@ -278,5 +281,4 @@ def analyze_items(items, category_id, agg_data): if __name__ == "__main__": print("Finding samples for SDK version %s" % ebaysdk.get_version()) (opts, args) = init_options() - run(opts) diff --git a/samples/t_http.py b/samples/t_http.py index 40433bb..229423f 100644 --- a/samples/t_http.py +++ b/samples/t_http.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' diff --git a/samples/test_perf.py b/samples/test_perf.py index 66cea2d..3e7feed 100644 --- a/samples/test_perf.py +++ b/samples/test_perf.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' diff --git a/samples/trading.py b/samples/trading.py index 06e2b1b..e0d724e 100644 --- a/samples/trading.py +++ b/samples/trading.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' @@ -39,6 +39,9 @@ def init_options(): parser.add_option("-c", "--certid", dest="certid", default=None, help="Specifies the eBay cert id to use.") + parser.add_option("-n", "--domain", + dest="domain", default='api.ebay.com', + help="Specifies the eBay domain to use (e.g. api.sandbox.ebay.com).") (opts, args) = parser.parse_args() return opts, args @@ -47,7 +50,7 @@ def init_options(): def run(opts): try: - api = Trading(debug=opts.debug, config_file=opts.yaml, appid=opts.appid, + api = Trading(debug=opts.debug, config_file=opts.yaml, appid=opts.appid, domain=opts.domain, certid=opts.certid, devid=opts.devid) api.execute('GetCharities', {'CharityID': 3897}) @@ -61,7 +64,7 @@ def run(opts): def feedback(opts): try: - api = Trading(debug=opts.debug, config_file=opts.yaml, appid=opts.appid, + api = Trading(debug=opts.debug, config_file=opts.yaml, appid=opts.appid, domain=opts.domain, certid=opts.certid, devid=opts.devid, warnings=False) api.execute('GetFeedback', {'UserID': 'tim0th3us'}) @@ -80,7 +83,7 @@ def feedback(opts): def getTokenStatus(opts): try: - api = Trading(debug=opts.debug, config_file=opts.yaml, appid=opts.appid, + api = Trading(debug=opts.debug, config_file=opts.yaml, appid=opts.appid, domain=opts.domain, certid=opts.certid, devid=opts.devid, warnings=False) api.execute('GetTokenStatus') @@ -96,7 +99,7 @@ def verifyAddItem(opts): """ try: - api = Trading(debug=opts.debug, config_file=opts.yaml, appid=opts.appid, + api = Trading(debug=opts.debug, config_file=opts.yaml, appid=opts.appid, domain=opts.domain, certid=opts.certid, devid=opts.devid, warnings=False) myitem = { @@ -167,7 +170,7 @@ def verifyAddItemErrorCodes(opts): """ try: - api = Trading(debug=opts.debug, config_file=opts.yaml, appid=opts.appid, + api = Trading(debug=opts.debug, config_file=opts.yaml, appid=opts.appid, domain=opts.domain, certid=opts.certid, devid=opts.devid, warnings=False) myitem = { @@ -244,7 +247,7 @@ def verifyAddItemErrorCodes(opts): def uploadPicture(opts): try: - api = Trading(debug=opts.debug, config_file=opts.yaml, appid=opts.appid, + api = Trading(debug=opts.debug, config_file=opts.yaml, appid=opts.appid, domain=opts.domain, certid=opts.certid, devid=opts.devid, warnings=True) pictureData = { @@ -264,7 +267,7 @@ def uploadPicture(opts): def uploadPictureFromFilesystem(opts, filepath): try: - api = Trading(debug=opts.debug, config_file=opts.yaml, appid=opts.appid, + api = Trading(debug=opts.debug, config_file=opts.yaml, appid=opts.appid, domain=opts.domain, certid=opts.certid, devid=opts.devid, warnings=True) # pass in an open file @@ -287,7 +290,7 @@ def uploadPictureFromFilesystem(opts, filepath): def memberMessages(opts): try: - api = Trading(debug=opts.debug, config_file=opts.yaml, appid=opts.appid, + api = Trading(debug=opts.debug, config_file=opts.yaml, appid=opts.appid, domain=opts.domain, certid=opts.certid, devid=opts.devid, warnings=True) now = datetime.datetime.now() @@ -325,7 +328,7 @@ def memberMessages(opts): def getUser(opts): try: - api = Trading(debug=opts.debug, config_file=opts.yaml, appid=opts.appid, + api = Trading(debug=opts.debug, config_file=opts.yaml, appid=opts.appid, domain=opts.domain, certid=opts.certid, devid=opts.devid, warnings=True, timeout=20, siteid='101') api.execute('GetUser', {'UserID': 'sallyma789'}) @@ -339,7 +342,7 @@ def getUser(opts): def getOrders(opts): try: - api = Trading(debug=opts.debug, config_file=opts.yaml, appid=opts.appid, + api = Trading(debug=opts.debug, config_file=opts.yaml, appid=opts.appid, domain=opts.domain, certid=opts.certid, devid=opts.devid, warnings=True, timeout=20) api.execute('GetOrders', {'NumberOfDays': 30}) @@ -353,7 +356,7 @@ def getOrders(opts): def categories(opts): try: - api = Trading(debug=opts.debug, config_file=opts.yaml, appid=opts.appid, + api = Trading(debug=opts.debug, config_file=opts.yaml, appid=opts.appid, domain=opts.domain, certid=opts.certid, devid=opts.devid, warnings=True, timeout=20, siteid='0') callData = { @@ -392,6 +395,6 @@ def categories(opts): uploadPictureFromFilesystem(opts, ("%s/test_image.jpg" % os.path.dirname(__file__))) memberMessages(opts) categories(opts) - + # getUser(opts) # getOrders(opts) diff --git a/setup.py b/setup.py index fc03578..71b8630 100644 --- a/setup.py +++ b/setup.py @@ -27,13 +27,6 @@ calls, response processing, error handling, debugging across the Finding, Shopping, Merchandising, & Trading APIs. """ -def requirements_file_to_list(fn="requirements.txt"): - """read a requirements file and create a list that can be used in setup. - """ - - with open(fn, 'r') as f: - return [x.rstrip() for x in list(f) if x and not x.startswith('#')] - setup( name=PKG, version=version, @@ -42,9 +35,9 @@ def requirements_file_to_list(fn="requirements.txt"): author_email="tkeefer@gmail.com", url="https://github.com/timotheus/ebaysdk-python", license="COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0", - packages=find_packages(), + packages=find_packages(include=['ebaysdk', 'ebaysdk.*']), provides=[PKG], - install_requires=['lxml', 'requests'], #requirements_file_to_list(), + install_requires=['lxml', 'requests'], test_suite='tests', long_description=long_desc, classifiers=[ diff --git a/tests/test_base.py b/tests/test_base.py index c27431d..389d9ea 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' diff --git a/tests/test_errors.py b/tests/test_errors.py new file mode 100644 index 0000000..22e257a --- /dev/null +++ b/tests/test_errors.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- + +''' +Copyright 2012-2019 eBay Inc. +Authored by: Tim Keefer +Licensed under CDDL 1.0 +''' + +from __future__ import absolute_import +import os +import unittest +import ebaysdk.shopping +import lxml + +os.environ.setdefault("EBAY_YAML", "ebay.yaml") + +class TestErrors(unittest.TestCase): + + def DISABLE_test_single_item(self): + connection = ebaysdk.shopping.Connection(version='799', config_file=os.environ.get('EBAY_YAML')) + + for i in range(20): + connection.execute('GetSingleItem', { + 'ItemID': '262809803926', + 'version': '981', + 'IncludeSelector': ['Variations'] + }) + self.assertEqual(connection.response.status_code, 200) + self.assertEqual(type(connection.response.dom()), lxml.etree._Element) + +if __name__ == '__main__': + unittest.main() + +""" +Variations262809803926981 +2017-02-28 06:18:42,156 ebaysdk [DEBUG]:total time=0.478377819061 +2017-02-28 06:18:42,156 ebaysdk [DEBUG]:execute: verb=GetSingleItem data={'ItemID': '262809803926', 'version': 981, 'IncludeSelector': 'Variations'} +2017-02-28 06:18:42,157 ebaysdk [DEBUG]:REQUEST (3ff5f071-04c3-40c0-a4f0-57f04a9e9972): POST http://open.api.ebay.com/shopping +2017-02-28 06:18:42,157 ebaysdk [DEBUG]:headers={'Content-Length': '219', 'X-EBAY-API-REQUEST-ENCODING': 'XML', 'X-EBAY-API-VERSION': '799', 'User-Agent': 'eBaySDK/2.1.4 Pytho +n/2.7.6 Linux/3.13.0-91-generic', 'X-EBAY-SDK-REQUEST-ID': '3ff5f071-04c3-40c0-a4f0-57f04a9e9972', 'X-EBAY-API-SITE-ID': '0', 'X-EBAY-API-CALL-NAME': 'GetSingleItem', 'Content +-Type': 'text/xml', 'X-EBAY-API-APP-ID': 'asdf'} +2017-02-28 06:18:42,157 ebaysdk [DEBUG]:body=Variations262809803926981 +2017-02-28 06:18:42,511 ebaysdk [DEBUG]:RESPONSE (3ff5f071-04c3-40c0-a4f0-57f04a9e9972): +2017-02-28 06:18:42,511 ebaysdk [DEBUG]:elapsed time=0:00:00.354254 +2017-02-28 06:18:42,511 ebaysdk [DEBUG]:status code=500 +2017-02-28 06:18:42,511 ebaysdk [DEBUG]:headers={'breadcrumbid': 'ID-slc4b03c-6483-stratus-slc-ebay-com-53764-1487075486325-0-1105919761', 'content-length': '25', 'accept-enco +ding': 'identity', 'x-ebay-api-request-encoding': 'XML', 'x-ebay-api-version': '799', 'user-agent': 'eBaySDK/2.1.4 Python/2.7.6 Linux/3.13.0-91-generic', 'connection': 'keep-a +live', 'x-ebay-sdk-request-id': '3ff5f071-04c3-40c0-a4f0-57f04a9e9972', 'x-ebay-api-site-id': '0', 'x-ebay-api-call-name': 'GetSingleItem', 'content-type': 'text/plain;charset +=utf-8', 'x-forwarded-for': '52.19.146.95', 'x-ebay-api-app-id': 'asdf'} +2017-02-28 06:18:42,511 ebaysdk [DEBUG]:content=an internal error occured +2017-02-28 06:18:42,512 ebaysdk [DEBUG]:response parse failed: Start tag expected, '<' not found, line 1, column 1 +ERROR - 2017-02-28 06:18:42,512 - utils.firehose_util - MainProcess - MainThread: Shopping Call error: {"ItemID": "262809803926", "version": 981, "IncludeSelector": "Variation +s"} +Traceback (most recent call last): + File "/home/ubuntu/logograb2-detection-server/utils/firehose_util.py", line 235, in make_ebay_request + r = Shopping(appid=app_id, config_file=None, debug=True).execute('GetSingleItem', api_pars) + File "/usr/local/lib/python2.7/dist-packages/ebaysdk/connection.py", line 124, in execute + self.error_check() + File "/usr/local/lib/python2.7/dist-packages/ebaysdk/connection.py", line 209, in error_check + estr = self.error() + File "/usr/local/lib/python2.7/dist-packages/ebaysdk/connection.py", line 321, in error + error_array.extend(self._get_resp_body_errors()) + File "/usr/local/lib/python2.7/dist-packages/ebaysdk/shopping/__init__.py", line 188, in _get_resp_body_errors + dom = self.response.dom() + File "/usr/local/lib/python2.7/dist-packages/ebaysdk/response.py", line 233, in dom + return self._dom + File "/usr/local/lib/python2.7/dist-packages/ebaysdk/response.py", line 220, in __getattr__ + return getattr(self._obj, name) +AttributeError: 'Response' object has no attribute '_dom' +""" diff --git a/tests/test_request.py b/tests/test_request.py index 1f60954..aba794c 100644 --- a/tests/test_request.py +++ b/tests/test_request.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ''' -© 2012-2013 eBay Software Foundation +Copyright 2012-2019 eBay Inc. Authored by: Tim Keefer Licensed under CDDL 1.0 ''' diff --git a/tox.ini b/tox.ini index 406235c..f15fd35 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27,py36 +envlist = py27,py37,py38 [testenv] setenv =