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 =
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 =
x3 = url3.getcode()

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

Recommended Answers

All 3 Replies

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

Thank you, but there was nothing usefull for me :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.