iSarabjitDhiman / TweeterPy

TweeterPy is a python library to extract data from Twitter. TweeterPy API lets you scrape data from a user's profile like username, userid, bio, followers/followings list, profile media, tweets, etc.
MIT License
169 stars 30 forks source link

session = None error and content-type error #64

Closed nballen-tx closed 6 months ago

nballen-tx commented 6 months ago

currently on version 1.14

with default session = None, it throws error session not defined. looks like a bug.

36 def save_session(filename=None, path=None, session=None): 37 if session is None: 38 raise NameError("name 'session' is not defined.") 39 if not isinstance(session, requests.Session): 40 raise TypeError(f"Invalid session type. {session} is not a requests.Session Object...")

NameError: name 'session' is not defined.

and also this error

2024-05-26 22:51:03,836 [INFO] :: API Updated Successfully. 2024-05-26 22:51:04,996 [ERROR] :: 'content-type'

Traceback (most recent call last): File "/opt/conda/lib/python3.9/site-packages/tweeterpy/request_util.py", line 31, in make_request if "json" in response.headers["Content-Type"]: File "/opt/conda/lib/python3.9/site-packages/requests/structures.py", line 52, in getitem return self._store[key.lower()][1] KeyError: 'content-type'

iSarabjitDhiman commented 6 months ago

Hmmm it works on my side. Note: you can only save the logged in sessions, not the guest sessions. Try this

from tweeterpy import TweeterPy
twitter = TweeterPy()
twitter.login("username","password")
twitter.save_session()

Let me know if this works

nballen-tx commented 6 months ago

thank you code works for me.

but i am using the old code called session_util.save_session

session_util.save_session(filename='AAA';, path='/home/notebook/', session=None)

where I can define a path to save the session.

for twitter.save_session(), looks like there is no way to define a file path?


save_session(session=None,session_name=None)

        Save a logged in session to avoid frequent logins in future.

        Args:
            session (requests.Session, optional): requests.Session object you want to save. If None, saves current session by default. Defaults to None.
            session_name (str, optional): Session name. If None, uses currently logged in username. Defaults to None.

        Returns:
            path: Saved session file path.
nballen-tx commented 6 months ago

ok actually just found it is defined here as

config.SESSION_DIRECTORY = '/home/notebook'