urllib

How to ignore windows proxy settings with python urllib?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 14:59:49
问题 I want Python to ignore Windows proxy settings when using urllib . The only way I managed to do that was disabling all proxy settings on Internet Explorer. Is there any programmatic way? os.environ['no_proxy'] is not a good option, since I'd like to avoid proxy for all addresses. 回答1: Pass to urlopen method proxies={} or try with: urllib.getproxies = lambda x = None: {} just after urllib import (Info found here). 回答2: From the urlib2 documentation: Class urllib2.ProxyHandler([proxies]) ... To

How to use Proxy PAC file for python urllib or request?

社会主义新天地 提交于 2019-12-10 13:56:36
问题 How do I include my automatic proxy config file in HTTP libraries like urllib or requests. pacfile = 'http://myintranet.com/proxies/ourproxies.pac' proxy = urllib3.ProxyManager(????????????????) 回答1: Current there is no support for a proxy PAC file directly in urllib3 or requests. While support could in principle be added for proxy PAC files, because they are Javascript files that require interpretation it is likely to be extremely difficult to provide broad-based support. In principle you

Downloading large file in python error: Compressed file ended before the end-of-stream marker was reached

假装没事ソ 提交于 2019-12-10 12:54:05
问题 I am downloading a compressed file from the internet: with lzma.open(urllib.request.urlopen(url)) as file: for line in file: ... After having downloaded and processed a a large part of the file, I eventually get the error: File "/usr/lib/python3.4/lzma.py", line 225, in _fill_buffer raise EOFError("Compressed file ended before the " EOFError: Compressed file ended before the end-of-stream marker was reached I am thinking that it might be caused by an internet connection that drops or the

How can I get the last-modified time with python3 urllib?

浪尽此生 提交于 2019-12-10 12:36:09
问题 I'm porting over a program of mine from python2 to python3, and I'm hitting the following error: AttributeError: 'HTTPMessage' object has no attribute 'getdate' Here's the code: conn = urllib.request.urlopen(fileslist, timeout=30) last_modified = conn.info().getdate('last-modified') This section worked under python 2.7, and so far I haven't been able to find out the correct method to get this information in python 3.1. The full context is an update method. It pulls new files from a server

“post” method to communicate directly with a server

别来无恙 提交于 2019-12-10 12:19:31
问题 Just started with python not long ago, and I'm learning to use "post" method to communicate directly with a server. A fun script I'm working on right now is to post comments on wordpress. The script does post comments on my local site, but I don't know why it raises HTTP Error 404 which means page not found. Here's my code, please help me find what's wrong: import urllib2 import urllib url='http://localhost/wp-comments-post.php' user_agent='Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'

Python requests error 10060

北战南征 提交于 2019-12-10 11:43:34
问题 I have a script that crawls a website. Untill today it ran perfect, However it does not do so now. it give sme the following error: Connection Aborted Error(10060 ' A connection attempt failed becvause the connected party did not properly respond after a period of time, or established a connection failed because connected host has failed to respond' I have been looking into answers ans settings but i cannot figure out how to fix this... In IE i am not using any Proxy (Connection -> Lan

HTTPS POST request Python, returning .csv

故事扮演 提交于 2019-12-10 11:15:56
问题 I want to make a post request to a HTTPS-site that should respond with a .csv file. I have this Python code: try: #conn = httplib.HTTPSConnection(host="www.site.com", port=443) => Gives an BadStatusLine: ' ' error conn = httplib.HTTPConnection("www.site.com"); params = urllib.urlencode({'val1':'123','val2':'abc','val3':'1b3'}) conn.request("POST", "/nps/servlet/exportdatadownload", params) content = conn.getresponse() print content.reason, content.status print content.read() conn.close()

How can I log in to facebook using python (requests/urllib3)?

萝らか妹 提交于 2019-12-10 10:54:41
问题 Im trying to use http://docs.python-requests.org/en/latest/ to log into facebook automatically. s = requests.session() params = {'email':'MYEMAILHERE','pass':'MYPASSHERE'} r = s.post("https://www.facebook.com/login.php/", params = params) print r.text But instead of fb showing me the home page it shows the me the "your cookies are disabled"... page. 回答1: Michael Heimlich made a project for integrating with the Facebook API using python-requests: https://github.com/michaelhelmick/requests

HTTP Error 403: Forbidden with urlretrieve

假装没事ソ 提交于 2019-12-10 10:54:06
问题 I am trying to download a PDF, however I get the following error: HTTP Error 403: Forbidden I am aware that the server is blocking for whatever reason, but I cant seem to find a solution. import urllib.request import urllib.parse import requests def download_pdf(url): full_name = "Test.pdf" urllib.request.urlretrieve(url, full_name) try: url = ('http://papers.xtremepapers.com/CIE/Cambridge%20IGCSE/Mathematics%20(0580)/0580_s03_qp_1.pdf') print('initialized') hdr = {} hdr = { 'User-Agent':

用python下载文件的若干种方法汇总

怎甘沉沦 提交于 2019-12-10 02:08:18
用python下载文件的若干种方法汇总 写文章 用python下载文件的若干种方法汇总 zhangqibot 发表于 MeteoAI 订阅 427 在这篇文章中: 1. 下载图片 2. 下载重定向的文件 3. 分块下载大文件 4. 并行下载多文件 5. 使用urllib获取html页面 6. python下载视频的神器 7. 举个例子 在日常科研或者工作中,我们免不了要批量从网上下载一些资料。要是手工一个个去下载,浪费时间又让鼠标折寿,好不容易点完了发现手指都麻木了。 这种重复性的批量作业我们应该交给python小弟去帮我们搞定,这篇文章汇总了用python下载文件的若干种方法,快点学起来吧。 1. 下载图片 import requests url = 'https://www.python.org/static/img/python-logo@2x.png' myfile = requests . get ( url ) open ( 'PythonImage.png' , 'wb' ) . write ( myfile . content ) 用 wget : import wget url = "https://www.python.org/static/img/python-logo@2x.png" wget . download ( url , 'pythonLogo