问题
The code generates a series of URLs and searches them for a specific string. As the website requires login information:
I logged in the website through my browsers.
And for more checks, I tried only one complete URL(of the same website) with no values and encoding and it worked perfectly well. So I supposed the login information shouldn't be the problem.
I did try to add log-in info through the code, but as it itself brought up a series of errors, I wanted to see if that is really necessary to work on. Maybe there is another solution with no need to log-in.
Lately, I understood the link is in "intranet" not "internet". Can that be the problem?
This is the code:
url ='https://www.aug.ipp.mpg.de/cgibin/sfread_only/isis?'
shotn = shot_a
#Shot_a, shot_z, diag and param are user inputs.
enter code here
while (shotn <= shot_z):
values = {'shot': shotn,
'exp': 'AUGD',
'diag': diag ,
'action': 'SignalDetails',
'signal': param}
data = urllib.parse.urlencode(values)
data = data.encode('utf-8')
req = urllib.request.Request(url, data)
resp = urllib.request.urlopen(req)
#The upper line is line 42- the first error
respData = resp.read()
shotn +=1
The expected result would be a .txt
file in the computer which includes the shotn's
which that specific statement was found in the corresponding URL.
And this is actual result:
Traceback (most recent call last):
File "C:/Users/lenovo/PycharmProjects/ url/venv/Final.py", line 42, in <module>
resp = urllib.request.urlopen(req)
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 531, in open
response = meth(req, response)
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 641, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 563, in error
result = self._call_chain(*args)
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 503, in _call_chain
result = func(*args)
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 734, in http_error_302
new = self.redirect_request(req, fp, code, msg, headers, newurl)
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 672, in redirect_request
raise HTTPError(req.full_url, code, msg, headers, fp)
urllib.error.HTTPError: HTTP Error 307: Temporary Redirect
Process finished with exit code 1
来源:https://stackoverflow.com/questions/57304591/http-error-307-temporary-redirect-in-python3-intranet