I tried it, and when checking it using a proxy, saw that it didn't really work, at least in the version that I have (urllib v1.17 and urllib2 v2.5). It just added that header onto the end, therefore making there two User-Agent headers, each with different values. I might add that my script IS able to retrieve search pages from Google, whereas both urllibs are FORBIDDEN with the headers that they use.
<br><br><div><span class="gmail_quote">On 4/8/07, <b class="gmail_sendername">Max Erickson</b> <<a href="mailto:maxerickson@gmail.com">maxerickson@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Subscriber123 <<a href="mailto:subscriber123@gmail.com">subscriber123@gmail.com</a>> wrote:<br>> urllib, or urllib2 for advanced users. For example, you can<br>> easily set your own headers when retrieving and serving pages,
<br>> such as the User-Agent header which you cannot set in either<br>> urllib or urllib2.<br><br>Sure you can. See:<br><br><a href="http://www.diveintopython.org/http_web_services/user_agent.html">http://www.diveintopython.org/http_web_services/user_agent.html
</a><br><br>(though the behavior was changed for python 2.3 to make setting the<br>user agent work better)<br><br><br>max<br><br><br>--<br><a href="http://mail.python.org/mailman/listinfo/python-list">http://mail.python.org/mailman/listinfo/python-list
</a><br></blockquote></div><br>