Fastest way for python HTTP GET request [closed] - python

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I'm developing a python script and I need to find the fastest way for getting a JSON from remote server. Currently I'm using requests module, but still requesting JSON is the slowest part of the script. So, what is the fastest way for python HTTP GET request?
Thanks for any answer.

Write a C module that does everything. Or fire up a profiler to find out in which part of the code the time is spent exactly and then fix that.
Just as guideline: Python should be faster than the network, so the HTTP request code probably isn't your problem. My guess is that you do something wrong but since you don't provide us with any information (like the code you wrote), we can't help you.

Maybe you have a lot of json requests to do, which can be done simultaneously. Then you can use async requests and thus mitigate the time spent waiting for network stuffs.
You can test this project https://github.com/kennethreitz/grequests (from Kenneth Reitz, who wrote requests).

Related

Need help on program that uses facebook/instagram info [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
A client wants to have information about public instagram/facebook profiles (photos/videos published, total likes/comments) from a period of time. How do I go about doing this?
I found out that some of that information is available in the website source code, but how do I use that information? Also is there any sites/services that does that already? The only ones I found only go as back as a few weeks, or only procress future posts.
I thought about automatizing the process with python, is it a good idea?
I'm new in programming, so any help is aprecciated.
As far as I know Instagram is trying to limit as much as possible bot activities, I'm not sure about Facebook though.
You can definitely try to webscrape (using python or other tools) the information you need but if things don't work, it may not be your fault.

A safe way to make an website run a python script [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I made a small script that solves an combinatorial optimization problem and I would like put it in a website so users can "play" with it, they could send a list of "points" to the server and this script would use a database to return the best combination of these "points".
The problem is I do not have much experience in web dev. I searched how to make an html button execute an script and I found this thread: https://stackoverflow.com/questions/48552343/how-can-i-execute-a-python-script-from-an-html-button#:~:text=To%20run%2C%20open%20command%20prompt,Hope%20this%20helpful.
But there says that an html button calling an python script is not safe. So what would be ideal What would be an ideal, safe alternative so that I could make sure that anyone who accesses my website can execute this script safely?
Well, there's no "easy" answer to your question. What you'd really need to do is to create a web-site in Python on your host computer – using a tool such as Django – and have one of the URLs supported by that website call your script.
Honestly, "what you're asking for here, really isn't the sort of question that StackOverflow is intended to answer." It's too big. Another one of the SE-family sites might be more appropriate, although I'm not quite sure which one ...
The solution that comes to mind would be setting up some Python-API (e.g. with Flask) which you could call with HTTP via JS, having different routes for different usages.
Here's a short overview of Flask showcasing how it could be used.

Creating a simple python web application [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a python script that takes inputs from commandline. I simply want to modify this script so I can run it on web. I want the commandline interface to be replaced by a simple boxes in a web page, and once the script is executed, I want the results to be shown on a webpage like it does in commandline.
Any help on where to start, which python packages to use and which steps to take would be much appreciated.
Until now, I read a little about webapp2 for Google App Engine and web.py. I do not want to use Django.
Thank you!
While you can use a microframework like Flask [1] for quickly getting started, you can get closer to the metal. Try learning about the HTTP protocol and implement your own server using the http module. Python 3's http.server contains a class SimpleHTTPServer [2] which can be very good for understanding how you're communicating between the client and your process.
[1] http://flask.pocoo.org/docs/0.12/quickstart/
[2] https://docs.python.org/2/library/simplehttpserver.html
Have you considered using Flask?
http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world
This is a pretty great tutorial on how to make a basic webapp.

Google maps API error handling [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm doing some test with the Google Maps Python API. The script is running fine, it loads GPS coordinates from a csv file and returns the address. It uses the googlemaps.reverse_geocode function.
However after a couple of "searches" I get an .....googlemaps.exceptions.TransportError: ('Connection aborted.....
It would be great if the script just continues when it receives an error.
I have no clue how to handle these error messages, the online documentation doesn't seem very clear about this.
One possibility is that you're using the free API which limits you to 10 requests per second, and you'r Python interpreter probably works a little bit faster, I would use a queue and a timer to fire up to 10 API requests per second. That would be the correct way to do the job if this is indeed the problem you're facing.
A straightforward solution to your problem would be using try and catch, so when the TransportError exception raises you'll know that you should time.sleep() for a while and retry the last API request before moving on to the next iteration.

how to implement request GET in Python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am having difficulties with the implementation of the query GET.
For example, I took no difficult task to bring in a convenient form the information on this page GET https://www.bitstamp.net/api/transactions/
Used API https://www.bitstamp.net/api/
I'm interested in everything from syntax to the modules you want to install for this request
Did you already seen this?
http://docs.python-requests.org/en/latest/
e.g:
import requests
response = requests.get(url)
print response.json()
If you don't want to install an extra library, you can use pythons urllib2 library that is just as easy for something like connecting to a url.
import urllib2
print urllib2.urlopen("https://www.bitstamp.net/api/transactions/").read()
For parsing that, use pythons json library.
There is a Python lib for that, the bitstamp-python-client. Do not waste your time reinventing the wheel. ;-)

Categories