Code works when run through powershell but not when run through IDE

42 Views Asked by At

Comparison of running directly in visual studio vs terminal option in visual studio I'm using a terminal profile with this command to set the venv:

-NoExit -Command "& { Import-Module """$env:VSAPPIDDIR\..\Tools\Microsoft.VisualStudio.DevShell.dll"""; Enter-VsDevShell -SkipAutomaticLocation -SetDefaultWindowTitle -InstallPath $env:VSAPPIDDIR\..\..\ ; C:\Users\James\source\repos\SolutionWikiRace\WikiRace\env\Scripts\Activate.ps1 ; cd C:\Users\James\source\repos\SolutionWikiRace\WikiRace\env\Scripts}"

I'm also in the venv when running the file through the IDE, I'm not getting any import errors. Running the script through right-clicking "Start with/without debugging" or setting it to be the initial file, then running it through the button at the top both result in the error. However, running it through the terminal option works. Running an external cmd session, running the command to start powershell in an env and then running the script also works.

I'm wondering what could the difference be between these operations, where running the file one way is fine and one runs an error. My current understanding is that there should no difference in the output because of how the script is being run. The script is written in python, and I don't use any relative filepaths in my code. The part that's causing an error is from an external library, pywikibot.

    ...292 more lines
    newpage = pywiki.Page(site, title=subpageurl, ns=2)
    newpage.text = wikitext
    newpage.save() #causes an error
    print("Whoop!") 

I have set usernames['wikipedia']['en'] = 'myUsername' like the error message requested, but even if there was an error in my or the library's code, how could the script being run through a different method change the result?

For reference, the entire error message when running through the IDE:

Traceback (most recent call last):   File "C:\Users\James\source\repos\SolutionWikiRace\WikiRace\env\lib\site-packages\pywikibot\login.py", line 101, in __init__
    user = code_to_usr.get(site.code) or code_to_usr['*'] KeyError: '*'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):   File "C:\Users\James\source\repos\SolutionWikiRace\WikiRace\env\lib\site-packages\pywikibot\page\_decorators.py", line 34, in handle
    func(self, *args, **kwargs)   File "C:\Users\James\source\repos\SolutionWikiRace\WikiRace\env\lib\site-packages\pywikibot\page\_basepage.py", line 1288, in _save
    done = self.site.editpage(self, summary=summary, minor=minor,   File "C:\Users\James\source\repos\SolutionWikiRace\WikiRace\env\lib\site-packages\pywikibot\site\_decorators.py", line 86, in callee
    return fn(self, *args, **kwargs)   File "C:\Users\James\source\repos\SolutionWikiRace\WikiRace\env\lib\site-packages\pywikibot\site\_apisite.py", line 1944, in editpage
    token = self.tokens['csrf']   File "C:\Users\James\source\repos\SolutionWikiRace\WikiRace\env\lib\site-packages\pywikibot\site\_tokenwallet.py", line 38, in __getitem__
    self.site.login()   File "C:\Users\James\source\repos\SolutionWikiRace\WikiRace\env\lib\site-packages\pywikibot\site\_apisite.py", line 419, in login
    login_manager = login.ClientLoginManager(site=self,   File "C:\Users\James\source\repos\SolutionWikiRace\WikiRace\env\lib\site-packages\pywikibot\login.py", line 103, in __init__
    raise NoUsernameError( pywikibot.exceptions.NoUsernameError: ERROR: username for wikipedia:en is undefined. If you have a username for that site, please add a line to user config file (user_config.py) as follows: usernames['wikipedia']['en'] = 'myUsername'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):   File "C:\Users\James\source\repos\SolutionWikiRace\WikiRace\WikiRace\Python_scripts\AbstractDistractions.py", line 295, in <module>
    newpage.save()   File "C:\Users\James\source\repos\SolutionWikiRace\WikiRace\env\lib\site-packages\pywikibot\page\_basepage.py", line 1276, in save
    self._save(summary=summary, watch=watch, minor=minor, botflag=botflag,   File "C:\Users\James\source\repos\SolutionWikiRace\WikiRace\env\lib\site-packages\pywikibot\page\_decorators.py", line 54, in wrapper
    handle(func, self, *args, **kwargs)   File "C:\Users\James\source\repos\SolutionWikiRace\WikiRace\env\lib\site-packages\pywikibot\page\_decorators.py", line 46, in handle
    raise OtherPageSaveError(self, err) pywikibot.exceptions.OtherPageSaveError: Edit to page [[en:User:Jamezofchez/WikiGame/Testing/United States]] failed: ERROR: username for wikipedia:en is undefined. If you have a username for that site, please add a line to user config file (user_config.py) as follows: usernames['wikipedia']['en'] = 'myUsername' CRITICAL: Exiting due to uncaught exception OtherPageSaveError: Edit to page [[en:User:Jamezofchez/WikiGame/Testing/United States]] failed: ERROR: username for wikipedia:en is undefined. If you have a username for that site, please add a line to user config file (user_config.py) as follows: usernames['wikipedia']['en'] = 'myUsername'
0

There are 0 best solutions below