http-request

Python requests exception handling

帅比萌擦擦* 提交于 2019-11-30 13:08:42
问题 How to handle exceptions with python library requests? For example how to check is PC connected to internet? When I try try: requests.get('http://www.google.com') except ConnectionError: # handle the exception it gives me error name ConnectionError is not defined 回答1: Assuming you did import requests , you want requests.ConnectionError . ConnectionError is an exception defined by requests . See the API documentation here. Thus the code should be : try: requests.get('http://www.google.com')

Send HTTP request from different IPs in Node.js

我与影子孤独终老i 提交于 2019-11-30 11:56:55
Is there a way to send an HTTP request with a different IP from what I have in Node.js? I want to send a request from an IP that I choose before, and not from the IP of the server or from my computer’s IP. I know that Tor Project does this kind of manipulation, but I didn't find any library that Tor uses to do this stuff. Is there any API or Node.js module that Tor uses to handle this kind of private browsing in Node.js? In the node http module there is a localAddress option for binding to specific network interface. var http = require('http'); var options = { hostname: 'www.example.com',

Django: Reading Array of JSON objects from QueryDict

狂风中的少年 提交于 2019-11-30 06:54:50
How do I pass a composite JSON structure via AJAX call from JS and on the server side, read it as a "very similar" data structure in python? I understand that json formatting can be used (simplejson etc), but I somehow feel that the QueryDict itself is malformed or reformatted in my case? Example: When passing an array of JSON objects [{"id": 1},{"id": 2},{"id": 3}] via AJAX to Django view, the QueryDict gets formatted as: POST:<QueryDict: {u'json_data[0][id]': [u'1'], u'type': [u'clone'], u'csrfmiddlewaretoken': [u'69bb3c434ced31ab301ede04bf491ec0'], u'json_data[1][id]': [u'2'], u'json_data[2

Sending multipart/form-data content with Postman Chrome extension

倾然丶 夕夏残阳落幕 提交于 2019-11-29 19:33:15
问题 I'm struggling with creating POST multipart/mixed request with Postman Chrome extension. I keep getting HTTP 500. Already gone through this question, but sadly solution doesn't works for me. Here is my curl request which works for me. curl -H "Content-Type: multipart/form-data" -F "merchantLogo=@offerlogo-320-320.png; type=image/png" -F "merchantDetails=@merchant.json; type=application/json" -X PATCH localhost:5000/api/merchants/57035bda0c74362faf5937f2/details -i -v And when I use Postman I

Send HTTP request from different IPs in Node.js

我的梦境 提交于 2019-11-29 17:35:00
问题 Is there a way to send an HTTP request with a different IP from what I have in Node.js? I want to send a request from an IP that I choose before, and not from the IP of the server or from my computer’s IP. I know that Tor Project does this kind of manipulation, but I didn't find any library that Tor uses to do this stuff. Is there any API or Node.js module that Tor uses to handle this kind of private browsing in Node.js? 回答1: In the node http module there is a localAddress option for binding

How to tell if a Request is coming from a Proxy?

倖福魔咒の 提交于 2019-11-29 15:11:55
问题 Is it possible to detect if an incoming request is being made through a proxy server? If a web application "bans" users via IP address, they could bypass this by using a proxy server. That is just one reason to block these requests. How can this be achieved? 回答1: IMHO there's no 100% reliable way to achieve this but the presence of any of the following headers is a strong indication that the request was routed from a proxy server: via: forwarded: x-forwarded-for: client-ip: You could also

Unknown encoding: idna in Python Requests

谁说我不能喝 提交于 2019-11-29 13:21:36
I'm using Python Requests. All works great but today I get this strange error: [...] File "/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/requests/models.py", line 321, in full_url netloc = netloc.encode('idna').decode('utf-8') LookupError: unknown encoding: idna Any ideas what could be wrong? I'm using Python 2.7.2 from brew. Try adding: import encodings.idna in various places to sift out other errors. I ran into this same problem working on a port of python to a new platform. We had only partial library support and unicodedata was missing which was causing imports of the idna

Make parallel libcurl HTTP requests

大兔子大兔子 提交于 2019-11-29 12:48:23
I have a question regarding the safety of performing parallel HTTP-requests using libcurl (C++). When reading this question, please bear in mind I have limited knowledge about HTTP-requests in general. Basically, let's say I have two (or more) threads, each thread makes a HTTP-request once per second. (All the requests made are to the same server). How does my program (or something else?) keep track of what HTTP-response belongs to which tread? I mean, can I be sure that if request A was sent from thread 1, and request B from thread 2 at the same time, and the responses are retrived at the

Using python requests library to login to website

穿精又带淫゛_ 提交于 2019-11-29 08:01:38
I have looked through many SO threads on how to create a session using the requests library, but none of the methods I tried actually log me in. I have very little experience with web design and protocols, so please point out any basics that I might need to understand. Here is what I'm doing: import requests EMAIL = 'my_email' PASSWORD = 'my_pw' URL = 'https://account.guildwars2.com/login' session = requests.session() login_data = dict(username=EMAIL, password=PASSWORD) r = session.post(URL, data=login_data) req = session.get('https://leaderboards.guildwars2.com/en/na/achievements/guild

Django: Reading Array of JSON objects from QueryDict

核能气质少年 提交于 2019-11-29 07:41:57
问题 How do I pass a composite JSON structure via AJAX call from JS and on the server side, read it as a "very similar" data structure in python? I understand that json formatting can be used (simplejson etc), but I somehow feel that the QueryDict itself is malformed or reformatted in my case? Example: When passing an array of JSON objects [{"id": 1},{"id": 2},{"id": 3}] via AJAX to Django view, the QueryDict gets formatted as: POST:<QueryDict: {u'json_data[0][id]': [u'1'], u'type': [u'clone'], u