Skip to content

Commit

Permalink
Fix urllib patch path (#1197)
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw authored Nov 8, 2024
1 parent 5f17121 commit 2bf4569
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions python/langsmith/_internal/_patch.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
# mypy: disable-error-code="import-untyped"
import functools

import six # noqa
from urllib3 import __version__ as urllib3version # noqa
from urllib3 import connection # noqa


def _ensure_str(s, encoding="utf-8", errors="strict") -> str:
if isinstance(s, str):
return s

if isinstance(s, bytes):
return s.decode(encoding, errors)
return str(s)


# Copied from https://github.com/urllib3/urllib3/blob/1c994dfc8c5d5ecaee8ed3eb585d4785f5febf6e/src/urllib3/connection.py#L231
def request(self, method, url, body=None, headers=None):
"""Make the request.
Expand Down Expand Up @@ -33,7 +41,7 @@ def request(self, method, url, body=None, headers=None):
else:
# Avoid modifying the headers passed into .request()
headers = headers.copy()
if "user-agent" not in (six.ensure_str(k.lower()) for k in headers):
if "user-agent" not in (_ensure_str(k.lower()) for k in headers):
headers["User-Agent"] = connection._get_default_user_agent()
# The above is all the same ^^^
# The following is different:
Expand Down
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "langsmith"
version = "0.1.141"
version = "0.1.142"
description = "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform."
authors = ["LangChain <support@langchain.dev>"]
license = "MIT"
Expand Down

0 comments on commit 2bf4569

Please sign in to comment.