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

Makes the the trading.py example compatible with Python 3.7 #264

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c71ba56
add tests
timotheus Apr 6, 2017
059cdd8
remove debugging
timotheus Apr 6, 2017
047223d
Revert "remove debugging"
timotheus Apr 11, 2017
bf47d4c
Create ebay.yaml
timotheus Apr 13, 2017
d91e374
pep8 fixes and added tests
timotheus Apr 27, 2017
123d012
Added str conversion of siteid
MoorsTech May 12, 2017
9d27b8e
Merge pull request #198 from MoorsTech/master
timotheus May 15, 2017
86985e3
Fix on issue #189
codeastar Jul 27, 2017
8060a75
Python 3.x compatibility update
codeastar Jul 27, 2017
1bab59b
updated trading sample
acjohnson Sep 30, 2017
6bacf63
fix setup.py ascii issue
timotheus Oct 13, 2017
9d28f5e
Add an option for domain to sample/findings.py so it can work with sa…
mthaddon May 4, 2018
b357af5
add storeMeta code to sample code
timotheus Jun 7, 2018
3cfc2eb
Merge pull request #245 from mthaddon/master
timotheus Jun 20, 2018
ff19b45
Make compatible with python 3
w- Jun 26, 2018
7f97b94
don't pass dict to smart_encode_request_data
w- Jun 26, 2018
26a101a
Logic Errors on previous commit
w- Jun 26, 2018
eaf7911
Merge pull request #248 from w-/patch-1
timotheus Sep 3, 2018
b53ddd3
update tox to use pycodestyle instead of pep8
timotheus Sep 3, 2018
5c1db7a
Merge branch 'master' of https://github.com/timotheus/ebaysdk-python
timotheus Sep 3, 2018
011c96a
Merge pull request #217 from acjohnson/samplefix
timotheus Sep 4, 2018
c977cd8
Revert "Make compatible with python 3"
timotheus Sep 5, 2018
0f9016b
Merge pull request #255 from timotheus/revert-248-patch-1
timotheus Sep 5, 2018
7198ac7
fix socket warning
timotheus Sep 5, 2018
7dda80c
add test that includes more unicode
timotheus Sep 5, 2018
2646013
Merge pull request #205 from codeastar/python3_compatibility
timotheus Sep 7, 2018
c00d225
update finding test and clean up lint errors
timotheus Sep 11, 2018
6c1f701
Makes the the trading.py example compatible with Python 3.7
NoahCardoza Feb 10, 2019
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ebay.yaml
timebay.yaml
build/
dist/
Expand All @@ -12,3 +13,4 @@ ebaysdk.egg-info/
\.tox
venv/
venv*
\.virtualenvs
27 changes: 27 additions & 0 deletions ebay.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: ebay_api_config

# Trading API Sandbox - https://www.x.com/developers/ebay/products/trading-api
api.sandbox.ebay.com:
compatability: 719
appid: ENTER_YOUR_APPID_HERE
certid: ENTER_YOUR_CERTID_HERE
devid: ENTER_YOUR_DEVID_HERE
token: ENTER_YOUR_TOKEN_HERE

# Trading API - https://www.x.com/developers/ebay/products/trading-api
api.ebay.com:
compatability: 719
appid: ENTER_YOUR_APPID_HERE
certid: ENTER_YOUR_CERTID_HERE
devid: ENTER_YOUR_DEVID_HERE
token: ENTER_YOUR_TOKEN_HERE

# 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
4 changes: 2 additions & 2 deletions ebaysdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import platform
import logging

__version__ = '2.1.4'
Version = __version__ # for backware compatibility
__version__ = '2.1.5'
Version = __version__ # for backward compatibility

try:
from logging import NullHandler
Expand Down
2 changes: 0 additions & 2 deletions ebaysdk/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ class Config(object):
"""Config Class for all APIs connections

>>> c = Config(domain='api.ebay.com')
>>> print(c.file())
ebay.yaml
>>> c.set('fname', 'tim')
>>> c.get('fname')
'tim'
Expand Down
6 changes: 6 additions & 0 deletions ebaysdk/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
True: 'https',
}

# Added compatibility for Python 3
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we had python 3 support covered already. Can you supply breaking test case that your commit is fixing?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was getting errors regarding basestring, and it appeared to be trying to .encode("utf-8") a dict. The test case was trying to run the example itself, uploading an image from the filesystem. At least on Mac OS High Sierra. I can reclone and run a few tests to double check that though. I'll get back to you ASAP.

try:
basestring
except NameError:
basestring = str


class BaseConnection(object):
"""Base Connection Class."""
Expand Down
3 changes: 2 additions & 1 deletion ebaysdk/finding/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -99,6 +99,7 @@ def __init__(self, **kwargs):
'finditemsbykeywordsresponse.categoryhistogramcontainer.categoryhistogram',
'finditemsbyproductresponse.categoryhistogramcontainer.categoryhistogram',
'finditemsinebaystoresresponse.categoryhistogramcontainer.categoryhistogram',
'finditemsinebaystoresresponse.categoryhistogramcontainer.categoryhistogram.childcategoryhistogram',
'findcompleteditemsresponse.aspecthistogramcontainer.aspect',
'finditemsadvancedresponse.aspecthistogramcontainer.aspect',
'finditemsbycategoryresponse.aspecthistogramcontainer.aspect',
Expand Down
9 changes: 6 additions & 3 deletions ebaysdk/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
Licensed under CDDL 1.0
'''
import sys
if sys.version_info[0] >= 3:
raise ImportError('grequests does not work with python3+')
from ebaysdk.exception import ConnectionError

# pylint: disable=import-error
import grequests
from ebaysdk.exception import ConnectionError
# pylint: enable=import-error

if sys.version_info[0] >= 3:
raise ImportError('grequests does not work with python3+')


class Parallel(object):
Expand Down
2 changes: 1 addition & 1 deletion ebaysdk/shopping/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, **kwargs):
uri -- API endpoint uri (default: /shopping)
appid -- eBay application id
siteid -- eBay country site id (default: 0 (US))
compatibility -- version number (default: 799)
version -- version number (default: 799)
https -- execute of https (default: True)
proxy_host -- proxy hostname
proxy_port -- proxy port number
Expand Down
18 changes: 0 additions & 18 deletions ebaysdk/soa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,6 @@ def load_from_app_config(self, app_config):
def response_dict(self):
return self.response.dict()

'''
if self._response_dict:
return self._response_dict

if self._response_content:

mydict = self.response.dict()

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

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

return self._response_dict
'''

def build_request_headers(self, verb):
return {
'Content-Type': self.config.get('content_type'),
Expand Down
4 changes: 2 additions & 2 deletions ebaysdk/trading/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ def build_request_headers(self, verb):
"X-EBAY-API-DEV-NAME": self.config.get('devid', ''),
"X-EBAY-API-APP-NAME": self.config.get('appid', ''),
"X-EBAY-API-CERT-NAME": self.config.get('certid', ''),
"X-EBAY-API-SITEID": self.config.get('siteid', ''),
"X-EBAY-API-SITEID": str(self.config.get('siteid', '')),
"X-EBAY-API-CALL-NAME": self.verb,
"Content-Type": "text/xml"
}
Expand Down Expand Up @@ -785,7 +785,7 @@ def _get_resp_body_errors(self):
.format(eClass=eClass, severity=eSeverity, code=eCode, shortMsg=eShortMsg,
longMsg=eLongMsg)

#from IPython import embed; embed()
# from IPython import embed; embed()

if eSeverity == 'Warning':
warnings.append(msg)
Expand Down
5 changes: 3 additions & 2 deletions ebaysdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def smart_encode_request_data(value):
try:
if sys.version_info[0] < 3:
return value

if type(value) == dict: # Added compatibility for Python 3
return {k: v.encode('utf-8') for (k, v) in value.items()}
return value.encode('utf-8')

except UnicodeDecodeError:
Expand Down Expand Up @@ -344,8 +345,8 @@ def perftest_dict2xml():

xml = dict2xml(sample_dict)

if __name__ == '__main__':

if __name__ == '__main__':
import timeit
print("perftest_dict2xml() %s" %
timeit.timeit("perftest_dict2xml()", number=50000,
Expand Down
11 changes: 7 additions & 4 deletions samples/finding.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +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
Expand All @@ -39,7 +42,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 = {
Expand All @@ -66,7 +69,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 = {
Expand All @@ -88,7 +91,7 @@ def run_unicode(opts):

def run2(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)

response = api.execute('findItemsByProduct',
Expand All @@ -103,7 +106,7 @@ def run2(opts):

def run_motors(opts):
api = finding(siteid='EBAY-MOTOR', debug=opts.debug, appid=opts.appid, config_file=opts.yaml,
warnings=True)
domain=opts.domain, warnings=True)

api.execute('findItemsAdvanced', {
'keywords': 'tesla',
Expand Down
Loading