Download von GIT mit Proxy Topic is solved

Stelle Fragen zur Programmierung mit Autohotkey

Moderator: jNizM

User avatar
Gerdi
Posts: 185
Joined: 03 Aug 2015, 18:48
Location: Germany
Contact:

Download von GIT mit Proxy

01 Dec 2018, 05:44

ich möchte https://github.com/Grrdi/ZackZackOrdner ... master.zip
via AHK von einem Geschäfts-Rechner, also in einer Proxy-Umgebung, herunterladen.
Habe dazu folgendes Skript vorbetreitet ( danke Automator http://the-automator.com/web-scraping-w ... hyperlink/):

Code: Select all

Download_File_XMLHTTP("https://raw.githubusercontent.com/Grrdi/ZackZackOrdner/master/ZackZackFensterBeispiel.jpg","ZackZackFensterBeispiel.jpg")
MsgBox
Download_File_XMLHTTP("https://github.com/Grrdi/ZackZackOrdner/archive/master.zip","c:\temp\ZackZackOrdner-master.zip")
MsgBox
Download_File_XMLHTTP(URL,File_Name:=""){
	if(File_Name="")
		SplitPath,URL,File_Name ;get file name from URL
	req:=ComObjCreate("MSXML2.XMLHTTP.6.0")
	ado:=ComObjCreate("ADODB.Stream")
	req.Open("HEAD",URL)
	req.Send() 
	ado.Type:=1
	req.Open("GET",URL,1),req.Send()
	while(req.ReadyState!=4){
		Sleep,50
	}
	ado.Open(),ado.Write(req.ResponseBody)
	ado.SaveToFile(File_Name,2)
	ado.Close()
}
mit dem Bild von Zeile 1 bzw. mit vielen anderen Downloads klappt dies auch
aber mit dem gewünschten Download Zeile 3 klappt dies nicht
Error: 0x800700005 - Zugriff verweigert
Source; msxml6.dll
Description: Zugriff verweigert.
Helpfile: (null)
HelpContext: 0
Specifically: Send ---> Verweis auf Zeile 12 req.Send()
Ich vermute, dass es etwas mit der Umbenennung die bei Git stattfindet zu tun hat (master.zip wird angefragt
und ZackZackOrdner-master.zip wird zurückgegeben) oder irgendetwas verschluckt sich an dem Minuszeichen in ZackZackOrdner-master.zip

Nachtrag: Betriebssystem Win 7 Proffesional
Win 10 Home (x64) and Win 11 Pro N
https://github.com/Grrdi/ZackZackOrdner/archive/master.zip --> get folders on the quick
garry
Posts: 3763
Joined: 22 Dec 2013, 12:50

Re: Download von GIT mit Proxy

02 Dec 2018, 07:23

hatte Erfolg (WIN-10)

Code: Select all

;-------- https://autohotkey.com/boards/viewtopic.php?f=5&t=43852 ---
;- user 'tmplinshi'
#warn
#NoEnv
setworkingdir,%a_scriptdir%
F1:="https://github.com/Grrdi/ZackZackOrdner/archive/master.zip"
fd:=a_desktop                                     ;- save here

whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.SetTimeouts(3000,3000,3000,3000)
global whr,fd

url:=WinHttp_UrlDownloadToFile(F1)
return
;----------------------------------------

;------------ urldownloadtofile user tmplinshi --------------------------------
WinHttp_UrlDownloadToFile(URL, Filename := "") {
	;WHR := ComObjCreate("WinHttp.WinHttpRequest.5.1")
	WHR.Open("GET", url, true)
	WHR.Send()
	WHR.WaitForResponse()

	if (Filename ~= "^\s*$") {
		try {
			RegExMatch( WHR.GetResponseHeader("Content-Disposition"), "filename=\K.+", Filename )
		} catch {
			RegExMatch( WHR.Option(1), "[^/]+$", Filename )    ;- 1 = WinHttpRequestOption_URL
		}
	}
	ADO := ComObjCreate("ADODB.Stream")
	ADO.Type := 1 ; adTypeBinary
	ADO.Open()
	ADO.Write(WHR.ResponseBody)
	ADO.SaveToFile(fd . "\" . FileName, 2)
	ADO.Close()
}
;========================================================================
just me
Posts: 9450
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Download von GIT mit Proxy

02 Dec 2018, 10:28

Moin,

ich habe mit der ZIP-Datei auch Probleme. Ich habe versucht, das auf das WinHttpRequest Objekt umzustellen. Mit der Bilddatei klappt das, mit der ZIP-Datei bekommen ich einen Fehler 0xC0000005 (Zugriff verweigert - entspricht Deinem 0x800700005) sobald ich versuche, auf das theoretisch in ResponseBody COM SAFEARRAY zuzugreifen. Eine Erklärung dafür habe ich leider nicht.

Schönen ersten Advent noch!
User avatar
Gerdi
Posts: 185
Joined: 03 Aug 2015, 18:48
Location: Germany
Contact:

Re: Download von GIT mit Proxy

02 Dec 2018, 13:24

Danke Garry,

auf meinem Geschäfts-Rechner (Win7) kommt :
Error: 0x80072EE2-
Source: WinHttp.WinHttpRequest
Description: Das Zeitlimit für den Vorgang wurde erreicht.
HelpFile: (null)
HelpContext: 0
Specifically: WaitForResponse

FehlerZeile: 022
Ein hochsetzen der Zeiten um das 10-Fache brachte außer einer längeren Wartezeit keine Änderung.

PS. der Download klappt manuell ausgeführt, wie er soll.

auf meinem Privat-PC Win10 klappt der Download ohne Fehlermeldung nicht.

Danke Just Me
Win 10 Home (x64) and Win 11 Pro N
https://github.com/Grrdi/ZackZackOrdner/archive/master.zip --> get folders on the quick
garry
Posts: 3763
Joined: 22 Dec 2013, 12:50

Re: Download von GIT mit Proxy

02 Dec 2018, 15:21

funtioniert bei mir , aber siehe Erfahrungen / Tips von user 'drugwash'
https://autohotkey.com/boards/viewtopic.php?f=5&t=55241

Code: Select all

;;- from user drugwash
;- https://autohotkey.com/boards/viewtopic.php?f=5&t=55241
#warn
#NoEnv
setworkingdir,%a_scriptdir%
fd:=a_desktop                                     ;- save here
hdr  := "Mozilla/5.0 (Windows NT 6.2; rv:47.0) Gecko/20100101 Firefox/47.0"
url1 := "https://github.com/Grrdi/ZackZackOrdner/archive/master.zip"    
SplitPath,url1, name, dir, ext, name_no_ext, drive
url2 := "https://github.com"                     ; Referrer URL, in case it's required
WHO  := ComObjCreate("WinHttp.WinHttpRequest.5.1")

try
{
WHO.Option(0) := hdr	      ; UserAgentString
WHO.Option(4) := 0x3300	      ; SslErrorIgnoreFlags (ignore all certificate errors)
WHO.Option(6) := 1			  ; EnableRedirects
WHO.Open("GET", url1, true)	                 ; async mode=true
;WHO.Open("GET", url1)
WHO.SetRequestHeader("Referer", url2)        ; URL2 as referrer
WHO.SetRequestHeader("User-Agent", hdr)
WHO.SetTimeouts(0, 60000, 30000, 120000)	 ; Resolve, Connect, Send, Receive.Timeout
WHO.Send()
WHO.WaitForResponse(120)	                 ; only in async mode
Responsebody := WHO.ResponseText
}
catch e 
{
xxx:=e.Message
msgbox, 262208,ERROR,Error=`n%xxx%
return
}


	ADO := ComObjCreate("ADODB.Stream")
	ADO.Type := 1 ; adTypeBinary
	ADO.Open()
	ADO.Write(WHO.ResponseBody)
	ADO.SaveToFile(fd . "\" . Name, 2)
	ADO.Close()
return
;=======================================================================
Last edited by garry on 03 Dec 2018, 08:09, edited 1 time in total.
User avatar
Gerdi
Posts: 185
Joined: 03 Aug 2015, 18:48
Location: Germany
Contact:

Re: Download von GIT mit Proxy

03 Dec 2018, 04:33

Berichtigung:
auf meinem Privat-PC Win10 klappt der Download ohne Fehlermeldung nicht.
klappt doch, habe ihn nur nicht gefunden, da Name und Ordner anderst als erwartet.

Danke Garry,
Ziel ist den Download mit Bord-Mitteln (also ohne Installation) hin zu bekommen.
eventuell steht das im Wiederspruch zu
hdr := "Mozilla/5.0 (Windows NT 6.2; rv:47.0) Gecko/20100101 Firefox/47.0"
Leider läuft der Geschäfts-PC wieder gegen einen Timeout:
Error: 0x80072EE2 -
Sorce: WinHttpRequest
Description: Das Zeitlimit für den Vorgang wurde erreicht.
HelpFile: (null)
HelpContext: 0
Specifically: WaitForResponse
Fehlerzeile: WHO.WaitForResponse(120)
Win 10 Home (x64) and Win 11 Pro N
https://github.com/Grrdi/ZackZackOrdner/archive/master.zip --> get folders on the quick
garry
Posts: 3763
Joined: 22 Dec 2013, 12:50

Re: Download von GIT mit Proxy

03 Dec 2018, 04:44

evtl Fragen an users : just me / drugwash / feiyue / bentschi etc ....
User avatar
Gerdi
Posts: 185
Joined: 03 Aug 2015, 18:48
Location: Germany
Contact:

Re: Download von GIT mit Proxy

03 Dec 2018, 07:14

Ich vermute dass mein Problem davon
https://support.microsoft.com/en-us/hel ... s-with-ser
betroffen ist.

Umschiffungen wilkommen!
Win 10 Home (x64) and Win 11 Pro N
https://github.com/Grrdi/ZackZackOrdner/archive/master.zip --> get folders on the quick
garry
Posts: 3763
Joined: 22 Dec 2013, 12:50

Re: Download von GIT mit Proxy

03 Dec 2018, 08:09

habe im script oben noch try / catch eingefügt
User avatar
Gerdi
Posts: 185
Joined: 03 Aug 2015, 18:48
Location: Germany
Contact:

Re: Download von GIT mit Proxy

03 Dec 2018, 09:03

Danke Gerry,
der Timeout-Fehler wird nun in der MsgBox angezeigt.
Win 10 Home (x64) and Win 11 Pro N
https://github.com/Grrdi/ZackZackOrdner/archive/master.zip --> get folders on the quick
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Download von GIT mit Proxy  Topic is solved

03 Dec 2018, 10:08

Beim Zugriff auf die .zip antwortet der Server mit 302 Found -> (Ein Redirect) und setzt mehrere Cookies.
Danach folgt ein Redirect auf eine andere URL von der die zip dann geladen wird.
Dein Bild wird direkt heruntergeladen.

Das ganze kann man in Chrome über die Entwicklerkonsole herausfinden.
Neues Tab -> F12 -> dann auf den Reiter networking -> url eintippen und dahin navigieren

Ich habe die folgenden Theorien:
Die Cookies können ein Problem sein und eventuell nicht mehr korrekt zurückgeschickt werden.
Das redirect musst du selber behandeln und daher nach der Redirect Antwort selber auf die neue URL wechseln.
Recommends AHK Studio
just me
Posts: 9450
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Download von GIT mit Proxy

03 Dec 2018, 10:50

Moin,

ich gebe jetzt auf. Ich hatte noch ein älteres WinHTTP-Skript. Das funktioniert hier auch klaglos mit der Bilddatei, aber nicht mit dem ZIP-Archiv:

Code: Select all

#NoEnv
SetWorkingDir, %A_ScriptDir%
FileName := "Download.zip.txt"
URL := "http://github.com/Grrdi/ZackZackOrdner/archive/master.zip"
; URL := "https://raw.githubusercontent.com/Grrdi/ZackZackOrdner/master/ZackZackFensterBeispiel.jpg"
FileDelete, %FileName%
If WinHttp_DownloadToFileBin(URL, FileName)
   MsgBox, Success!
Else
   MsgBox, Error!
ExitApp

WinHttp_DownloadToFileBin(Url, FileName) {
   WHR := ComObjCreate("WinHttp.WinHttpRequest.5.1")
   WHR.SetTimeouts(0, 60000, 30000, 120000)
   WHR.Open("GET", Url, True)
   WHR.Send()
   WHR.WaitForResponse(120)
   ResponseLength := WHR.ResponseBody.MaxIndex() + 1
   FileLength := 0
   VarSetCapacity(Index, 4, 0)
   PtrOfIndex := 0
   Try {
      DllCall("OleAut32.dll\SafeArrayPtrOfIndex", "Ptr", ComObjValue(WHR.ResponseBody), "Ptr", &Index, "PtrP", PtrOfIndex)
      hFile := FileOpen(FileName, "w")
      hFile.RawWrite(PtrOfIndex + 0, ResponseLength)
      FileLength := hFile.Pos
      hFile.Close()
   }
   Catch E
      MsgBox, 0, %A_ThisFunc%, % E.What . ":`n" . E.Message . "`n" .  E.Extra
   Return FileLength
}
Fehler: 0xc0000005 bei DllCall("OleAut32.dll\SafeArrayPtrOfIndex", ...)

Eigenartigerweise lässt sich das SAFEARRAY aber mit einer For Schleife abarbeiten. Und wenn man das tut, kann damit anscheinend eine korrekte ZIP-Datei erstellt werden:

Code: Select all

#NoEnv
SetWorkingDir, %A_ScriptDir%
FileName := "Download.zip"
URL := "http://github.com/Grrdi/ZackZackOrdner/archive/master.zip"
; URL := "https://raw.githubusercontent.com/Grrdi/ZackZackOrdner/master/ZackZackFensterBeispiel.jpg"
FileDelete, %FileName%
If WinHttp_DownloadToFileBin(URL, FileName)
   MsgBox, Success!
Else
   MsgBox, Error!
ExitApp

WinHttp_DownloadToFileBin(Url, FileName) {
   WHR := ComObjCreate("WinHttp.WinHttpRequest.5.1")
   WHR.SetTimeouts(0, 60000, 30000, 120000)
   WHR.Open("GET", Url, True)
   WHR.Send()
   WHR.WaitForResponse(120)
   ResponseLength := WHR.ResponseBody.MaxIndex() + 1
   ; Achtung, wenn das aufgemacht wird, kann es dauern!
   VarSetCapacity(Response, ResponseLength, 0)
   Addr := &Response
   For Value, Type In WHR.ResponseBody
      Addr := NumPut(Value, Addr + 0, "UChar")
   FileLength := 0
   VarSetCapacity(Index, 4, 0)
   PtrOfIndex := 0
   Try {
      hFile := FileOpen(FileName, "w")
      hFile.RawWrite(&Response, ResponseLength)
      FileLength := hFile.Pos
      hFile.Close()
   }
   Catch E
      MsgBox, 0, %A_ThisFunc%, % E.What . ":`n" . E.Message . "`n" .  E.Extra
   Return FileLength
}
Wer macht hier wann und warum was falsch? :roll:
User avatar
Gerdi
Posts: 185
Joined: 03 Aug 2015, 18:48
Location: Germany
Contact:

Re: Download von GIT mit Proxy

03 Dec 2018, 12:37

Danke nnnik,
redirect zu anderer URL, war der entscheidende Tip.
Mit

Code: Select all

Download_File_XMLHTTP("https://codeload.github.com/Grrdi/ZackZackOrdner/zip/master","ZackZackOrdner-master.zip")
bin ich auch auf dem Geschäfts-PC erfolgreich.

Danke auch JustMe
ich muss Deine Aktionen allerdings erst noch sichten.

PS. https://github.com/Grrdi/ZackZackOrdner ... Ordner.ahk installiert oder aktualisiert und startet https://www.autohotkey.com/boards/viewt ... 10&t=15248 nun auch in Proxy-Umgebungen.
Falls jemand eine Umgebung hat, bei welcher der Download fehlschlägt, bitte ich um Meldung hier in diesem Beitrag.
Win 10 Home (x64) and Win 11 Pro N
https://github.com/Grrdi/ZackZackOrdner/archive/master.zip --> get folders on the quick

Return to “Ich brauche Hilfe”

Who is online

Users browsing this forum: 355 113, Rohwedder and 40 guests