Skip to content

Commit 8b4ea4d

Browse files
Merge pull request #360 from stripe/ob-fix-329
Fix BytesWarning with Python 3
2 parents 571b26a + f416185 commit 8b4ea4d

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ install:
2626
- python setup.py install
2727
script:
2828
- if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then flake8 stripe; fi
29-
- python -W all setup.py test
29+
- python -W all -bb -W error::BytesWarning setup.py test
3030
matrix:
3131
allow_failures:
3232
- python: 3.7-dev

stripe/util.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ def dashboard_link(request_id):
114114

115115
def logfmt(props):
116116
def fmt(key, val):
117+
# Handle case where val is a bytes or bytesarray
118+
if sys.version_info[0] == 3 and hasattr(val, 'decode'):
119+
val = val.decode('utf-8')
117120
# Check if val is already a string to avoid re-encoding into
118121
# ascii. Since the code is sent through 2to3, we can't just
119122
# use unicode(val, encoding='utf8') since it will be

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ deps =
1414
mock
1515
commands =
1616
python setup.py clean --all
17-
python -W all setup.py test {posargs}
17+
python -W all -bb -W error::BytesWarning setup.py test {posargs}
1818
setenv =
1919
STRIPE_TEST_PYCURL = true
2020

@@ -28,4 +28,4 @@ deps =
2828
commands =
2929
flake8 stripe
3030
python setup.py clean --all
31-
python -W all setup.py test {posargs}
31+
python -W all -bb -W error::BytesWarning setup.py test {posargs}

0 commit comments

Comments
 (0)