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

Don't use os.chdir() #18

Closed
DreiPixel opened this issue Dec 6, 2020 · 5 comments
Closed

Don't use os.chdir() #18

DreiPixel opened this issue Dec 6, 2020 · 5 comments
Labels
bug Something isn't working

Comments

@DreiPixel
Copy link

Describe the bug
i trying to make a script and it either relies on os.getcwd() or "./"
"./" doesnt work since i get a WinError 3 "Path doesnt exists" from the downloader
and os.getcwd() works once but if run it again (with while or for loop or run the downloader multiple times in a scrip) your module changes the working directory to the given path to the downloader.

To Reproduce
Steps to reproduce the behavior:

  1. use path = "os.getcwd() + "\Download" to get a path.
  2. set path with reddit.path = path
  3. download a video.
    4 now os.getcwd() returns the path C:\(runningdirectory\Download\ resulting in a recursion each time a video is downloaded.

Expected behavior
not getting a recursion

Desktop (please complete the following information):

  • OS: Windows (will happen with any os)

Additional context
it works if you dont set the path variable multiple times. but in my case i need too.
i could just get the initial working directory and store that in a variable that never gets changed.

@elmoiv
Copy link
Owner

elmoiv commented Dec 7, 2020

Can you please send a copy of the script you used that caused this bug?

@DreiPixel
Copy link
Author

DreiPixel commented Dec 7, 2020

here is a small example script with that bug.
workaround is easy but shouldn't be really neede imo

https://pastebin.com/uXED49v8

@elmoiv
Copy link
Owner

elmoiv commented Dec 7, 2020

Thanks.
I will try to fix this issue ASAP.

@elmoiv elmoiv added the bug Something isn't working label Dec 7, 2020
@nkmathew
Copy link

nkmathew commented Jan 5, 2021

Yeah I'm also getting this problem. Sometimes it raises an exception without ever restoring the directory breaking any other part of your code that replies on relative paths:

redvid/redvid/redvid.py

Lines 62 to 81 in b9eb2e4

os.makedirs('temp', exist_ok=True)
os.chdir('temp')
# Allow v.redd.it url formats
if 'v.redd.it' in self.url:
self.url = self.get(
self.url,
_proxies=self.proxies
).url
self.page = self.get(
toJsonUrl(self.url),
_proxies=self.proxies
)
if self.page.status_code is 200:
return True
raise BaseException('Incorrect URL format')

@elmoiv
Copy link
Owner

elmoiv commented Jan 5, 2021

I updated redvid with new fixes. Now pip install redvid==1.1.2.

@elmoiv elmoiv closed this as completed Jan 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants