refactor: replace requests_async w/ httpx

This commit is contained in:
Brian Berg 2020-07-12 02:40:39 +00:00
parent 74d9f14439
commit df20a0686d
3 changed files with 10 additions and 11 deletions

View File

@ -8,6 +8,6 @@
"@brianberg" "@brianberg"
], ],
"requirements": [ "requirements": [
"requests_async" "httpx"
] ]
} }

View File

@ -8,8 +8,8 @@ References:
from datetime import datetime from datetime import datetime
from hashlib import sha256 from hashlib import sha256
import hmac import hmac
import httpx
import json import json
import requests_async as requests
import sys import sys
from time import mktime from time import mktime
import uuid import uuid
@ -75,12 +75,12 @@ class NiceHashPublicClient:
if query is not None: if query is not None:
url += f"?{query}" url += f"?{query}"
async with requests.Session() as session: async with httpx.AsyncClient() as client:
if body: if body:
data = json.dumps(body) data = json.dumps(body)
response = await session.request(method, url, data=data) response = await client.request(method, url, data=data)
else: else:
response = await session.request(method, url) response = await client.request(method, url)
if response.status_code == 200: if response.status_code == 200:
return response.json() return response.json()
@ -134,8 +134,8 @@ class NiceHashPrivateClient:
"X-Request-Id": str(uuid.uuid4()), "X-Request-Id": str(uuid.uuid4()),
} }
async with requests.Session() as session: async with httpx.AsyncClient() as client:
session.headers = headers client.headers = headers
url = NICEHASH_API_URL + path url = NICEHASH_API_URL + path
if query: if query:
@ -145,9 +145,9 @@ class NiceHashPrivateClient:
print(method, url) print(method, url)
if data: if data:
response = await session.request(method, url, data=data) response = await client.request(method, url, data=data)
else: else:
response = await session.request(method, url) response = await client.request(method, url)
if response.status_code == 200: if response.status_code == 200:
return response.json() return response.json()

View File

@ -3,6 +3,5 @@
"domains": [ "domains": [
"sensor" "sensor"
], ],
"iot_class": "Cloud Polling", "iot_class": "Cloud Polling"
"homeassistant": "0.108.0"
} }