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 9 years ago.
Improve this question
I would like to learn how to use jsonp with python. I googled around for any useful tutorial. However, it seems that there are no so much resources up there.
Thus I would like to ask here if anybody knows any tutorial, API that I can use, or any best practices.
Thank you.
Do you mean supporting the generation of JSOP output with a Python-powered API or website?
That's pretty easy to support. Say your API at /some/resource.json already outputs some JSON encoded data (say, in the code it's a return json.dumps(dict(a='foo'))).
To support JSONP all you have to do is accept a callback parameter (say /some/resource.json&callback=some_func). Now, if you get this parameter, instead of returning just the json serialized data, you wrap it in a function call:
d = json.dumps(dict(a='foo'))
return 'some_func(' + d + ');'
That way, calling web-client code can simply auto insert script tags in its DOM to magically load your javascript 'function'. Make sense?
Related
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 4 years ago.
Improve this question
I'm in dire need of getting started with REST JSON API, possibly with python.
Already purchased the subscription to use the API. How can I make a REST request?
Below is an excerpt from the documentation.
REST Request
https://smartmover.melissadata.net/v3/WEB/SmartMover/doSmartMover
?t={Transmission Reference}
&id={License Key}
&jobid={Job ID}
&pafid={PAF ID}
&act={Actions}
&cols={Columns}
&opt={Options}
&List={List Name}
&comp={Company}
&full={Name Full}
&first={Name First}
&Middle={Name Middle}
&Namepre={Name Prefix}
&Namesfx={Name Suffix}
&last={Name Last}
&u={Urbanization}
&a1={Address Line 1}
&a2={Address Line 2}
&ste={Suite}
&pmb={Private Mailbox}
&city={City}
&state={State}
&postal={Postal Code}
&plus4={Plus4}
&ctry={Country}
&format={Format}
Thanks for any help!!!!
The question is a bit vague, and opinion-based, but I'll give you some directions to seek:
First of all, just get some grasp of HTTP and REST API concepts overall. Wiki may be a good starting point
If your looking for non-programmatic HTTP API client, take a look at httpie. The good thins is that it gives you a glimpse of what's going on lower-ish level, while maintaining really good balance of detail vs simple interface (not grapic interface, tho). As a bonus, its written in python
For programmatic use (this is probably what you looking for), I suggest using requests library. It has awesome interface, and IMO it's standard de-facto in modern python. Easy to use, easy to understand how to use it with your API, handles a lot of routine stuff for you, easy to subclass/inherit.
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 6 years ago.
Improve this question
I am writing a wrapper function for a web API right now and the API expects the date to be input in a particular format (YYYY-MM-DD). I am wondering how to notify the wrapper user if the the input format is incorrect?
My thoughts:
Let the API itself take care of it and simply return what the API
returns
This takes care of any future changes in the API
Write a handler in the wrapper and if the input is incorrect, then
simply return the HTTP error code 400 (Bad Request).
The users often have a restriction of number of API requests per day and this would help them from wasting them because of invalid input.
EDIT
As pointed out in the comments, the decision depends on my take on maintenance. Can you also tell me is the general good practice or should one look at these situations on case by case basis?
Remember:
A wrapper function is a subroutine in a software library or a computer program whose main purpose is to call a second subroutine or a system call with little or no additional computation.
As found on Wikipedia.
Therefore I suggest you doing the first thing, letting the API handle it. Whenever I use a wrapper, I only ever want to look at the Documentation of the actual API, not the wrapper. It also seems a lot more intuitive to me.
Good luck :)
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
In reference towards me question, how would one be able to input data and retrieve data from various websites (not using an API)?
Is there a module that searches or acts like a human for purposes as in searching along applicably given fields; in effort to (as said before) retrieve data?
Sorry if I'm making my question hard to follow along; though if so, here's an example of what I am trying to accomplish:
Directing an AI towards a specific website.
Inputting data into the search field.
Then finally, retrieving said data after previously ran processes.
I'm fairly new to the section or field in manipulating websites via APIs or various (unknown) code; therefore, sorry if I missed anything!
You can use
mechanize,
BeautifulSoup,
Urllib,
Urllib2,
modules in Python. What I suggest you is use mechanize module. It is like scraping website through python program. More over simply a browser through python code.
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 have a python script written up and the output of this script is a list . Right now I need to get it online and make it accesible to others. I looked at Django , but then I realised that it may be kind of hard to create the UI. Is there any simple way to create a UI in Django and map it to an existing python script. Right now I am not using sql and things like that. Or is there a simpler way by which I can proceed?
I'd go with Flask or web.py.
Django pays off if you develop a large app; yours is not.
Probably all you need is two pages: one with an input form, and another with results. As long as your input is text, you should have little trouble taking input from a POST handler and passing it as is to your script.
Both microframeworks have tutorials: here's web.py's, and Flask's is right on the home page. Should get you started very quickly.
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 5 years ago.
Improve this question
I have a huge C file (~100k lines) which I need to be able to parse. Mainly I need to be able to get details about individual fields of every structure (like field name and type for every field in the structure) from its definition. Is there a good(open source, which i can use in my code) way to do this already? Or should I write my own parser for this. If I have to write my own, can anyone suggest a good place to start? I have never worked with python before.
Thanks
Take a look at this link for an extensive list of parsing tools available for Python. Specifically, for parsing c code, try the pycparser
The right way to do this is almost certainly to interface with the front-end of an existing compiler, such as gcc, then work with the intermediate representation, rather than attempting to create your own parser, in any language.
However, pycparser, as suggested by Dhara might well be a good substitute, and definitely better than any attempt to roll your own.