1

The addresses I am trying to open look like this:
"//usa-qa/QAEngr/QA_Team_VSripathi/Negar/Help files/broken/header_test/main.htm"

They are located on a company's internal network.

I tried this piece of code:

 import urllib  
 import urllib.request as ur  
 address="//usa-qa/QAEngr/QA_Team_VSripathi/Negar/Help files/broken/header_test/main.htm"  
 info=ur.urlopen(address)

which results in the following error:

Traceback (most recent call last):  
  File "C:/Users/naref/Desktop/networktest.py", line 14, in <module>  
    info=ur.urlopen(address)  
  File "C:\Python33\lib\urllib\request.py", line 160, in urlopen  
    return opener.open(url, data, timeout)  
  File "C:\Python33\lib\urllib\request.py", line 458, in open  
    req = Request(fullurl, data)  
  File "C:\Python33\lib\urllib\request.py", line 279, in __init__  
    self._parse()  
  File "C:\Python33\lib\urllib\request.py", line 284, in _parse  
    raise ValueError("unknown url type: %s" % self.full_url)  
ValueError: unknown url type: //usa-qa/QAEngr/QA_Team_VSripathi/Negar/Help files/broken/header_test/main.htm 

The same happens when converting the path to url:

info=ur.urlopen(ur.pathname2url(address))

Then I tried to add an "http:" to the beginning of the address:

address="http://usa-qa/QAEngr/QA_Team_VSripathi/Negar/Help files/broken/header_test/main.htm"  
info=ur.urlopen(address)

Which results in the following error:

Traceback (most recent call last):
  File "C:/Users/naref/Desktop/networktest.py", line 14, in <module>  
    info=ur.urlopen(address)  
  File "C:\Python33\lib\urllib\request.py", line 160, in urlopen  
    return opener.open(url, data, timeout)  
  File "C:\Python33\lib\urllib\request.py", line 473, in open  
    response = self._open(req, data)  
  File "C:\Python33\lib\urllib\request.py", line 491, in _open  
    '_open', req)  
  File "C:\Python33\lib\urllib\request.py", line 451, in _call_chain  
    result = func(*args)  
  File "C:\Python33\lib\urllib\request.py", line 1272, in http_open  
    return self.do_open(http.client.HTTPConnection, req)  
  File "C:\Python33\lib\urllib\request.py", line 1255, in do_open  
    raise URLError(err)  
urllib.error.URLError:<urlopen error [WinError 10061] No connection could be made because the target machine actively refused it>

It is interesting that this problem gets solved when I map the network drive on my computer which runs windows 8: (http://windows.microsoft.com/en-us/windows-8/create-shortcut-to-map-network-drive)

Also the file can be opened with the open function instead of the urlopen, however I prefer to use urlopen since for my purpose the address might be a website's url.

na1368
  • 127
  • 9
  • your code does not correspond to the traceback. Try `urllib.parse.urljoin('file:', urllib.request.pathname2url(address))`. – jfs Feb 20 '15 at 17:07
  • I also made a small change to the first piece of code that I have. It as showing the address start with http: which was wrong, it starts with // – na1368 Feb 20 '15 at 18:24
  • J. F. I tried the piece of code you suggested. I get this error: – na1368 Feb 20 '15 at 18:27
  • . File "C:\Python33\lib\urllib\request.py", line 491, in _open '_open', req) File "C:\Python33\lib\urllib\request.py", line 451, in _call_chain result = func(*args) File "C:\Python33\lib\urllib\request.py", line 1378, in file_open return self.open_local_file(req) File "C:\Python33\lib\urllib\request.py", line 1418, in open_local_file raise URLError(msg) urllib.error.URLError: – na1368 Feb 20 '15 at 18:27
  • 1
    don't put the relevant info into the comments, [edit] your question instead. – jfs Feb 20 '15 at 18:38
  • Yeah I did J. F. I was just informing you about the change in the comments. – na1368 Feb 20 '15 at 21:35
  • I don't see *"The system cannot find the path specified"* error in the question. Create the minimal code example that shows the issue: `open(address)` should succeed, use [the suggested code](http://stackoverflow.com/questions/28634107/python-how-to-open-urls-html-files-which-are-located-on-an-internal-network#comment45568674_28634107) to get url, print the url, `urllib.request.urlopen(url)` should fail, post the full traceback in the question. – jfs Feb 21 '15 at 04:00

0 Answers0