Skip to content

Commit ee55ec1

Browse files
committed
fix: Allow unicode strings for DSN under Py2
1 parent b0eda8b commit ee55ec1

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

sentry_sdk/client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
def _get_options(*args, **kwargs):
3535
# type: (*Optional[str], **Any) -> Dict[str, Any]
36-
if args and (isinstance(args[0], str) or args[0] is None):
36+
if args and (isinstance(args[0], (text_type, bytes, str)) or args[0] is None):
3737
dsn = args[0] # type: Optional[str]
3838
args = args[1:]
3939
else:

tests/test_client.py

+20
Original file line numberDiff line numberDiff line change
@@ -659,3 +659,23 @@ def __repr__(self):
659659
exception, = event["exception"]["values"]
660660
frame, = exception["stacktrace"]["frames"]
661661
assert frame["vars"]["environ"] == {"a": "<This is me>"}
662+
663+
664+
@pytest.mark.parametrize(
665+
"dsn",
666+
[
667+
"http://894b7d594095440f8dfea9b300e6f572@localhost:8000/2",
668+
u"http://894b7d594095440f8dfea9b300e6f572@localhost:8000/2",
669+
],
670+
)
671+
def test_init_string_types(dsn, sentry_init):
672+
# Allow unicode strings on Python 3 and both on Python 2 (due to
673+
# unicode_literals)
674+
#
675+
# Supporting bytes on Python 3 is not really wrong but probably would be
676+
# extra code
677+
sentry_init(dsn)
678+
assert (
679+
Hub.current.client.dsn
680+
== "http://894b7d594095440f8dfea9b300e6f572@localhost:8000/2"
681+
)

0 commit comments

Comments
 (0)