Skip to content

fix(twitter): remove redundant inner 'import os' causing UnboundLocalError on configure#185

Closed
Panniantong wants to merge 1 commit intomainfrom
fix/twitter-configure-os-unbound
Closed

fix(twitter): remove redundant inner 'import os' causing UnboundLocalError on configure#185
Panniantong wants to merge 1 commit intomainfrom
fix/twitter-configure-os-unbound

Conversation

@Panniantong
Copy link
Owner

Problem

Fixes #183

agent-reach configure twitter-cookies "auth_token=...; ct0=..." prints:

✅ Twitter cookies configured!
[!] Could not sync to xreach session.json: cannot access local variable 'os' where it is not associated with a value

Root Cause

Inside _cmd_configure(), the twitter-cookies branch has a nested import os (line 954, inside a try block for the xreach test step):

else:
    import os          # ← the problem
    env = os.environ.copy()

Python's scoping rules treat any name binding (including import) as local to the entire function. So the module-level import os at line 15 was shadowed, making every os.xxx call before the inner import (line 927–941: os.path.join, os.makedirs, os.path.exists, os.chmod) raise:

UnboundLocalError: cannot access local variable 'os' where it is not associated with a value

Fix

Remove the redundant import os line — os is already imported at module level.

Verification

  • python3 -c "import agent_reach.cli" → OK
  • python3 -m pytest tests/ -x -q49 passed

…Error

The twitter-cookies configure handler had 'import os' inside an inner
try/except block (line 954). Python's scoping rules treat any binding of
a name in a function scope as local for the *entire* function — so the
top-level 'import os' at line 15 was shadowed, making every 'os.xxx'
call before the inner import raise:

  UnboundLocalError: cannot access local variable 'os'
  where it is not associated with a value

Fix: remove the redundant inner 'import os'; 'os' is already imported
at module level and is accessible throughout cli.py.

Fixes #183
@Panniantong
Copy link
Owner Author

Closing — this fix is no longer needed after PR #196 refactored the cookie parsing logic into a standalone helper function. The redundant import os was removed as part of that refactor. Thanks! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

X好像有点问题

1 participant