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

Why I get “PermissionError: [WinError 5] Access is denied” error when I using youtube-dl in c# process class? #10766

Closed
parsasaei opened this issue Sep 26, 2016 · 28 comments

Comments

@parsasaei
Copy link

@parsasaei parsasaei commented Sep 26, 2016

PermissionError: [WinError 5] Access is denied

  • When I run youtube-dl.exe with c# process class on server, it returns below error in StandardOutput:

Traceback (most recent call last): File "__main__.py", line 19, in <module> File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmpc7h_sle1\build\youtube_dl\__init__.py", line 449, in main File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmpc7h_sle1\build\youtube_dl\__init__.py", line 416, in _real_main File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmpc7h_sle1\build\youtube_dl\YoutubeDL.py", line 367, in __init__ File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmpc7h_sle1\build\youtube_dl\YoutubeDL.py", line 2100, in _setup_opener File "C:\Users\dst\AppData\Roaming\Build archive\youtube-dl\rg3\tmpc7h_sle1\build\youtube_dl\utils.py", line 642, in make_HTTPS_handler File "C:\Python\Python34\lib\ssl.py", line 439, in create_default_context File "C:\Python\Python34\lib\ssl.py", line 390, in load_default_certs File "C:\Python\Python34\lib\ssl.py", line 377, in _load_windows_store_certs PermissionError: [WinError 5] Access is denied

My Version is youtube-dl --version: 2016.0.31.0 and also when I used latest version,this problem was occured too.

  • I've verified and I assure that I'm running youtube-dl 2016.0.31.0

What is these errors?I don't have these paths and files with these directories.
And Here is my code

string ydlPath = Server.MapPath("/ydlPath/youtube-dl.exe");
string tempLocation = Server.MapPath("/ydlPath/");

    System.IO.StreamReader errorreader;
    System.Diagnostics.Process proc = new System.Diagnostics.Process();
    proc.EnableRaisingEvents = false;
    proc.StartInfo.ErrorDialog = false;
    proc.StartInfo.RedirectStandardError = true;
    proc.StartInfo.FileName = ydlPath ;
    //proc.StartInfo.Arguments = "-F \"" + Url + "\"";
    proc.StartInfo.WorkingDirectory = tempLocation;
    proc.StartInfo.Arguments = "-f bestvideo[ext=mp4]+bestaudio[ext=m4a] \"" + Url + "\"";
    proc.StartInfo.Verb = "runas";
    proc.StartInfo.UseShellExecute = false;
    proc.StartInfo.CreateNoWindow = false;
    proc.StartInfo.RedirectStandardOutput = true;
    proc.Start();
    errorreader = proc.StandardError;
    string Output = proc.StandardOutput.ReadToEnd();

    proc.WaitForExit();
    proc.Close();

My Description

I used this on my local and it works fine. Also when I use youtube-dl.exe with cmd on server or on my local I don't have problem.

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Sep 26, 2016

Are you using IIS? It's a Python bug. Could you install Python 2.7.12 or 3.5.2 and use the zipped version of youtube-dl?

@parsasaei
Copy link
Author

@parsasaei parsasaei commented Sep 26, 2016

@yan12125 Yes,I'm using iis,and I installed python 3.4.0 in C:\Python\Python34\ Matching with error sayed.

@parsasaei
Copy link
Author

@parsasaei parsasaei commented Sep 26, 2016

@yan12125 How can I install this zipped version?

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Sep 26, 2016

Download that file, then

C:\PythonXY\python.exe C:\some\directory\youtube-dl
@parsasaei
Copy link
Author

@parsasaei parsasaei commented Sep 26, 2016

@yan12125 What should I type In cmd? I ask this question because when I use this in cmd, I can configure it on my server code.
I mean command code for dl is like ablout this:

C:\PythonXY\python.exe C:\some\directory\youtube-dl -f bestvideo[ext=mp4]+bestaudio[ext=m4a] **YoutubeVideoLink**
@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Sep 26, 2016

Just replace the path to python.exe and youtube-dl to real paths. Anything wrong?

@parsasaei
Copy link
Author

@parsasaei parsasaei commented Sep 26, 2016

@yan12125 Thank you very much.It worked with your beneficial helps.
After install python 3.5 in c:\Python35
I use it in my code :

string ydlPath = @"C:\Python35\python.exe";
string ydl = @"C:\YoutubeDownload\ydlPath\youtube-dl";
string tempLocation = Server.MapPath("/ydlPath/");
        System.IO.StreamReader errorreader;
        System.Diagnostics.Process proc = new System.Diagnostics.Process();
        proc.EnableRaisingEvents = false;
        proc.StartInfo.ErrorDialog = false;
        proc.StartInfo.RedirectStandardError = true;
        proc.StartInfo.FileName = ydlPath ;
        //proc.StartInfo.Arguments = "-F \"" + Url + "\"";
        proc.StartInfo.WorkingDirectory = tempLocation;
        proc.StartInfo.Arguments = ydl + " -f bestvideo[ext=mp4]+bestaudio[ext=m4a] \"" + Url + "\"";
        proc.StartInfo.Verb = "runas";
        proc.StartInfo.UseShellExecute = false;
        proc.StartInfo.CreateNoWindow = false;
        proc.StartInfo.RedirectStandardOutput = true;
        proc.Start();
        errorreader = proc.StandardError;
        string Output = proc.StandardOutput.ReadToEnd();

    proc.WaitForExit();
    proc.Close();

Thank You.

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Sep 26, 2016

Glad to see that fixed :)

@yan12125 yan12125 closed this Sep 26, 2016
@parsasaei
Copy link
Author

@parsasaei parsasaei commented Oct 18, 2016

@yan12125 With this compressed python version,I can't download from somelinks,but with exe version it's work.
How can I handle it? can I?
have this compressed python a new version for this isssue or I should do anything?

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Oct 18, 2016

@parsasaei Could you post the command line output of both versions?

@parsasaei
Copy link
Author

@parsasaei parsasaei commented Oct 18, 2016

@yan12125 yes. exe version download file and here exists output of it:

[youtube] MZctQy6uEo8: Downloading webpage
[youtube] MZctQy6uEo8: Downloading video info webpage
[youtube] MZctQy6uEo8: Extracting video information
[download] Destination: Come Alive-MZctQy6uEo8.f137.mp4
[download] 100% of 7.56MiB in 00:35
[download] Destination: Come Alive-MZctQy6uEo8.f140.m4a
[download] 100% of 4.48MiB in 00:20
[ffmpeg] Merging formats into "Come Alive-MZctQy6uEo8.mp4"
Deleting original file Come Alive-MZctQy6uEo8.f137.mp4 (pass -k to keep)
Deleting original file Come Alive-MZctQy6uEo8.f140.m4a (pass -k to keep) 

but python compressed output is empty and not return anything.
and here is this youtube link which I want to download it :https://www.youtube.com/watch?v=MZctQy6uEo8

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Oct 18, 2016

How did you run the compressed version?

@parsasaei
Copy link
Author

@parsasaei parsasaei commented Oct 18, 2016

With process class of c#

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Oct 18, 2016

Could you paste relevant C# codes?

@parsasaei
Copy link
Author

@parsasaei parsasaei commented Oct 18, 2016

In top of this topic it's there

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Oct 18, 2016

Nothing printed to StandardError either?

@parsasaei
Copy link
Author

@parsasaei parsasaei commented Oct 18, 2016

it's print:
ERROR: MZctQy6uEo8: YouTube said: This video is not available.

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Oct 18, 2016

For https://www.youtube.com/watch?v=MZctQy6uEo8, I got "This video is not available." here too. Does the exe version and the Python version run on the same PC?

@parsasaei
Copy link
Author

@parsasaei parsasaei commented Oct 18, 2016

No.It's different.I check exe version my local pc,and check python verion on server

@parsasaei
Copy link
Author

@parsasaei parsasaei commented Oct 18, 2016

On server, exe vesrion return YouTube said: This video is not available too.

@parsasaei
Copy link
Author

@parsasaei parsasaei commented Oct 18, 2016

What is the reason of it?is it related to location ip?

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Oct 18, 2016

Yes, and I guess you need a proxy on the server. From the youtube page, it says only the following countries are allowed to watch this video: AS,AU,BE,CA,DK,FI,FR,GB,GU,IE,IS,KR,LU,MP,MX,NL,NO,NZ,PR,SE,US,VI. Full names for those abbreviations can be found in http://data.okfn.org/data/core/country-list

@parsasaei
Copy link
Author

@parsasaei parsasaei commented Oct 18, 2016

My server location is on "United States, Illinois, Chicago", and with this recommendation,it must be download.

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Oct 18, 2016

Does your server allow running browsers? (IE, edge, etc.) If so could you open https://www.youtube.com/watch?v=MZctQy6uEo8 and check whether it plays or not?

@parsasaei
Copy link
Author

@parsasaei parsasaei commented Oct 18, 2016

It can't open on browser of server.

@parsasaei
Copy link
Author

@parsasaei parsasaei commented Oct 18, 2016

Sorry, my server location is on Netherlands but Netherlands exists in list of countries which can access to watch this video too.

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Oct 18, 2016

youtube-dl tries its best to mimic browsers. If you got "This video is not available" in youtube-dl, I bet you'll get the same in browsers. You may want to ask Google why blocking your server. AFAIK there are reports that geolocation detection misbehaves.

@parsasaei
Copy link
Author

@parsasaei parsasaei commented Oct 18, 2016

Thank you so much.

jezzdk pushed a commit to jezzdk/youtube-dl-php that referenced this issue Aug 31, 2017
… for use cases where the youtube-dl executable is run with python, ie. when running under IIS. Similar problem described here: ytdl-org/youtube-dl#10766
norkunas added a commit to norkunas/youtube-dl-php that referenced this issue Aug 31, 2017
… for use cases where the youtube-dl executable is run with python, ie. when running under IIS. Similar problem described here: ytdl-org/youtube-dl#10766 (#40)
@ThePirate42 ThePirate42 mentioned this issue Mar 21, 2020
3 of 3 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.