Skip to content

Commit 9ace5b5

Browse files
author
clickingbuttons
authored
User agent version (#161)
* try dynamic version * add version to user agent string * add types for setuptools
1 parent eb32b3f commit 9ace5b5

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

poetry.lock

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

polygon/rest/base.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
from enum import Enum
66
from typing import Optional, Any, Dict
77
from datetime import datetime
8+
import pkg_resources # part of setuptools
9+
10+
version = pkg_resources.require("polygon-api-client")[0].version
811

912

1013
class BaseClient:
@@ -31,7 +34,7 @@ def __init__(
3134
num_pools=num_pools,
3235
headers={
3336
"Authorization": "Bearer " + self.API_KEY,
34-
"User-Agent": "Python client",
37+
"User-Agent": "Python client " + version,
3538
},
3639
ca_certs=certifi.where(),
3740
cert_reqs="CERT_REQUIRED",

polygon/websocket/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,11 @@ async def connect(
7777
if self.verbose:
7878
print("connect:", self.url)
7979
# darwin needs some extra <3
80-
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
81-
ssl_context.load_verify_locations(certifi.where())
80+
ssl_context = None
81+
if self.url.startswith("wss://"):
82+
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
83+
ssl_context.load_verify_locations(certifi.where())
84+
8285
async for s in connect(
8386
self.url, close_timeout=close_timeout, ssl=ssl_context, **kwargs
8487
):

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ sphinx-rtd-theme = "^1.0.0"
3939
# keep this in sync with docs/requirements.txt for readthedocs.org
4040
sphinx-autodoc-typehints = "^1.18.1"
4141
types-certifi = "^2021.10.8"
42+
types-setuptools = "^57.4.14"
4243

4344
[build-system]
4445
requires = ["poetry-core>=1.0.0"]

0 commit comments

Comments
 (0)