天道酬勤,学无止境

python-requests

Time-delayed grequests without using grequests.map()

This is the first time I've tried to use a library with less-than-ideal levels of documentation and example code, so bear with me. I have a tiny bit of experience with the Requests library, but I need to send separate requests to a specific address every second: Without waiting for the first request to complete, handling the individual responses as they come in The responses' content need to be parsed separately While limiting the total number of connections I can't figure out how to satisfy these conditions simultaneously. grequests.map() will give me the responses' content that I want, but

2021-06-21 11:36:00    分类:问答    python   python-requests   grequests

python requests upload file

I'm visiting a website and I want to upload a file. I wrote the code in python: import requests url = 'http://example.com' files = {'file': open('1.jpg', 'rb')} r = requests.post(url, files=files) print(r.content) But it seems no file has been uploaded, and the page is the same as the initial one. I wonder how I could upload a file. The source code of that page: <html><head><meta charset="utf-8" /></head> <body> <br><br> Upload<br><br> <form action="upload.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="hidden" name="dir" value="/uploads/" />

2021-06-15 13:47:24    分类:问答    python   post   upload   python-requests

requests process hangs

I'm using requests to get a URL, such as: while True: try: rv = requests.get(url, timeout=1) doSth(rv) except socket.timeout as e: print e except Exception as e: print e After it runs for a while, it quits working. No exception or any error, just like it suspended. I then stop the process by typing Ctrl+C from the console. It shows that the process is waiting for data: ............. httplib_response = conn.getresponse(buffering=True) #httplib.py response.begin() #httplib.py version, status, reason = self._read_status() #httplib.py line = self.fp.readline(_MAXLINE + 1) #httplib.py data = self

2021-06-15 13:30:07    分类:问答    python   python-requests

SSLError (Read operation timed out) in Python requests

I have a python API script and my script sometimes gets terminated on this line despite using try/except. Here is the code: try: r = requests.post(URL, data=params, headers=headers, timeout=self.request_timeout) try: response = r.json() except Exception, e: message = "ERROR_0104! Unexpected error occured. The error is: " message += str(e) print message aux_func.write_log(message) return 'Switch' except requests.exceptions.RequestException: print "Exception occurred on 'API requests post' procedure." counter += 1 continue ... The error occurs on the second line of above shown code. This is the

2021-06-15 11:10:03    分类:问答    python   ssl   python-requests

HTTP Digest/Basic Auth with Python Requests module

My goal here is to be able to parse html/xml data from a password protected page then based on that data (a timestamp) I need to send xml commands to another device. The page I am trying to access is a webserver generated by an IP device. Also, if this would be easier to accomplish in another language please let me know. I have very little experience programming (one C programming class) I have tried using Requests for Basic and Digest Auth. I still can't get authenticated, which is stopping me from getting any further. Here are my attempts: import requests from requests.auth import

2021-06-15 04:05:55    分类:问答    xml   http   python-3.x   python-requests   digest-authentication

How to make POST request in robobrowser-python

http://robobrowser.readthedocs.org/en/latest/api.html I'm trying to hit an API using browser.open(myurl) and looking for a RB method similar to requests.post(url,data=data). since robobrowser built on the top of requests and beautifulsoup so I think there must be a way to do so.

2021-06-15 03:53:02    分类:问答    python   python-2.7   python-requests   robobrowser

Compressing request body with python-requests?

(This question is not about transparent decompression of gzip-encoded responses from a web server; I know that requests handles that automatically.) Problem I'm trying to POST a file to a RESTful web service. Obviously, requests makes this pretty easy to do: files = dict(data=(fn, file)) response = session.post(endpoint_url, files=files) In this case, my file is in a really highly-compressible format (yep, XML) so I'd like to make sure that the request body is compressed. The server claims to accept gzip encoding (Accept-Encoding: gzip in response headers), so I should be able to gzip the

2021-06-14 19:45:09    分类:问答    python   http   gzip   python-requests

Python Requests HTTPConnectionPool and Max retries exceeded with url

On a Linux cluster, I get this error with Requests: ConnectionError: HTTPConnectionPool(host='andes-1-47', port=8181): Max retries exceeded with url: /jammy/api/v1 (Caused by : '') What does this error mean? Is it a Requests problem or is it on the host, and what is the solution? By the way, the program works successfully on both Windows and Linux standalone machines with localhost.

2021-06-13 18:51:06    分类:问答    python   python-requests

Python email module ImportError: No module named utils

My installation of Python's requests library has been working perfectly for months and it has decided to break today. Python 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import requests Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.7/dist-packages/requests/__init__.py", line 58, in <module> from . import utils File "/usr/local/lib/python2.7/dist-packages/requests/utils.py", line 26, in <module> from .compat import parse_http_list as _parse_list_header

2021-06-13 17:24:31    分类:问答    python-2.7   python-requests

Python : UnicodeEncodeError when I use grep

I am using a simple python script to get reservation results for my CID : simple.py: data = {"minorRev":"current minorRev #","cid":"xxx","apiKey":"xxx","customerIpAddress":" ","creationDateStart":"03/31/2013","} url = 'http://someservice/services/rs/' req = requests.get(url,params=data) print req print req.text print req.status_code Now on the command prompt if I do python simple.py it runs perfectly and prints the req.text variable However when I try to do python simple.py | grep pattern I get UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 1314: ordinal not in

2021-06-13 15:40:26    分类:问答    python   grep   python-requests