Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove requests dependency from ClientTransaction class #270

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions twikit/x_client_transaction/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import random
import base64
import hashlib
import requests
from typing import Union, List
from functools import reduce
from .cubic_curve import Cubic
Expand Down Expand Up @@ -56,10 +55,10 @@ async def get_indices(self, home_page_response, session, headers):
key_byte_indices = list(map(int, key_byte_indices))
return key_byte_indices[0], key_byte_indices[1:]

def validate_response(self, response: Union[bs4.BeautifulSoup, requests.models.Response]):
if not isinstance(response, (bs4.BeautifulSoup, requests.models.Response)):
def validate_response(self, response: bs4.BeautifulSoup):
if not isinstance(response, bs4.BeautifulSoup):
raise Exception("invalid response")
return response if isinstance(response, bs4.BeautifulSoup) else bs4.BeautifulSoup(response.content, 'lxml')
return response

def get_key(self, response=None):
response = self.validate_response(response) or self.home_page_response
Expand Down Expand Up @@ -158,7 +157,3 @@ def generate_transaction_id(self, method: str, path: str, response=None, key=Non
out = bytearray(
[random_num, *[item ^ random_num for item in bytes_arr]])
return base64_encode(out).strip("=")


if __name__ == "__main__":
pass