Python 3.2.2
I want to check HTTP status code (eg. 200 or 404) on some www application. There are five server, and each server have a copy of this www application (The user is automatically redirected to the application on the server with low traffic/sometimes on random server). Suppose that the name of servers is: 0,1,2,3,4 I tried various options, three of them I pasted below (they works -always return 200, but choose not this server what I want):

import urllib.request,urllib.parse, http.cookiejar
values2= {"server":"2"}
data2 = urllib.parse.urlencode(values2)
data2 = data2.encode("utf-8")
request2 = urllib.request.Request(url,data2)
cj2 = http.cookiejar.CookieJar()
urlOpener2 = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj2))
url2 = urlOpener2.open(request2)
x2 = url2.getcode()


import urllib.request
headers1 = {"Set-Cookie":"serwer=2"}
req1 = urllib.request.Request(url, None, headers1)
t1 = urllib.request.urlopen(req1)
coderesp1 = t1.getcode()


import urllib.request
urlOpener3 = urllib.request.build_opener()
urlOpener3.addheaders.append(("Set-Cookie", "serwer=2"))
url3 = urlOpener3.open(url)
x3 = url3.getcode()

If you will have some questions about my problem, please write, I will immediately reply what you want to know.

6 Years
Discussion Span
Last Post by khukln-k

I want to check HTTP status code on page of www application on a particular server (which I choose).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.