Setting up a Python ViewServer for CouchDB - python

I am trying to get up to speed with CouchDB. As a relatively new user on Python, I am trying to set up a view-server so that I can pass on python functions to couchdb.design.ViewDefinitions function. As I understand, ViewDefinitions take javascript code to execute map/reduce function.
Here is what I struggle to understand - I am well aware that this might be a basic question. According to wiki (http://wiki.apache.org/couchdb/View_server):
To register query servers with CouchDB, add a line for each server to local.ini. The basic syntax is:
'[query_servers] python=/usr/bin/couchpy'
How do I access local.ini file? I am an 10.6.8 Mac user. Thanks!
Update: Thank you Kxepal. It seems I was able to create the design/view on Futon in Python. Alternatively, I figured that python viewserver can be created as follows:
curl -X PUT http://[localhost]/_config/query_servers/python '"/path/to/couchpy"'
However, I still cannot execute the python script. Running the view on Couch results in following:
'Error: An error occurred accessing the view no response'
I would appreciate if somebody can point in the right direction. Thanks!

I encountered the same "Error: An error occurred accessing the view no response" problem, and it turned out to be a bug in my python code. Specifically, in the javascript implementation I had something like:
function (doc) {
emit(doc.somefield, doc);
}
I had converted this to:
def map(doc):
yield doc.somefield, doc
However, this gave me the "no response" error you describe.
Changing it to the following fixed the problem.
def map(doc):
yield doc['somefield'], doc

I don't know there OSX keeps CouchDB config files, but you always may setup Python query server through Futon. On sidebar click Configuration, than "Add section" at the bottom of the page and fill the fields with same data as you planned to write into local.ini. As bonus, you don't need restart CouchDB - configuration changes through HTTP API are applied instantly, but be sure that you'd specified correct values.

Related

Show Server details via Python OpenStack API using the nova client

I am trying to convert my BASH script to Python and am having difficulties in finding the equivalent code for openstack server show or openstack server list --long. I would like to know what host is my server currently located and use this information for a check before migrating it to another host.
Looking through the latest novaclient documentation and its servers module, I have found two potential commands that I was hoping would accomplish the task, but does not do so:
list(detailed=True)
Gets a list servers
detailed=True should return detailed server info (optional).
This returns a regular list of servers with their names.
get(server)
Get a server
This returns only the name of the server.
I have been researching for the past two days, and I could not find the same / similar problem here in stack overflow so I have decided to ask and I am hoping that someone can help me with this.
Either list or get should be fine here.
As an example get would be used like this.
instance = nova_client.servers.get('my-server')
print(instance.name)
print(instance.addresses)
print(instance.status)
Or using list.
for instance in nova_client.servers.list():
print(instance.name)
print(instance.addresses)
print(instance.status)
If you want an easy way of understanding the type of data you can get, you can simply use the Python inbuilt dir.
instance = nova_client.servers.get('my-server')
print(dir(instance))
'my-server' needs to be the id as in instance.id, the name of the server is not valid.
I cant yet comment, so i wrote an answer.

IBM Cloud functions - Unable to create an action

I'm unable to create an IBM Cloud action. I have no idea why.
My IBM data that I get in console is as follows:
API endpoint: https://api.eu-gb.bluemix.net
Region: eu-gb
User: my-name#my-company.com
Account: My Name's Account (12fcae9b137946b8bbfe481448612345)
Resource group: Default
CF API endpoint: https://api.eu-gb.bluemix.net (API version: 2.92.0)
Org: my-org
Space: dev
That look fine to me.
When I execute the test action as the docs says here as follows:
ibmcloud wsk action invoke whisk.system/utils/echo -p message hello --result
I get correct result:
{
"message": "hello"
}
But I'm not able to create my own actions.
The folder looks as follows:
Thus there is .zip file that I created with
zip -r as24-crawler.zip virtualenv commmon.py __main__.py
And now when I try to create an action as the docs says here with
ibmcloud wsk action create my-action-name --kind python:3 as24-crawler.zip
I got an error as follows:
error: Unable to create action 'my-action-name': The connection
failed, or timed out. (HTTP status code 413)
Any idea what am I doing wrong?
UPDATE
Is the file size to big? I'm not sure. The error message is not clear but the meaning could be that the file to big is.
They say in the docs that the limit is 48MB. But my created .zip file is 43.6MB. Thus I assume that that not the problem is.
I am one of the guys responsible for IBM Cloud Functions.
We have been looking into this issue and must admit that this is a bug (causing zip files to be rejected even if the are smaller than the documented 48MB limit); we are already working on a fix to get this resolved asap.
In the meantime you may want to have a look at the workaround (which allows you to "outsource" some of your dependencies etc.) described here:
http://jamesthom.as/blog/2017/08/04/large-applications-on-openwhisk/
I hope this helps - feel free to contact me (e.g. via Linkedin/Twitter, see my profile information) directly in case you have further questions or in case you want to discuss anything else.
Thanks for having found and reported this issue and sorry for inconvenience.
it seems according to the return code '413' the provided data used to create the action is too large. To get an indication about the system limits you might want to check IBM Cloud Functions documentation here: https://console.bluemix.net/docs/openwhisk/openwhisk_reference.html#openwhisk_syslimits.

InterfaceError: Error binding Parameter 5...Django JWT token (django request token tool)

I am trying to set up a "one time use" link creating system with this tool:
https://github.com/yunojuno/django-request-token
I have followed the instructions on the installation and implementation. Now the implementation says that I should create a Requesttoken in the admin interface or with some other method.
When I go to the admin interface and when I go to add the token, I fill out the scope field which is the only one required and click save. This is where I get the
InterfaceError:r: Error binding Parameter 5 - probably unsupported type
And the error seems to happen at this line of code:
super(RequestToken, self).save(*args, **kwargs)
Now I will include the models.py file:
https://github.com/yunojuno/django-request-token/blob/master/request_token/models.py
This is the file which contains the line of code which is causing the error.
I am really stuck on this and I hope someone will know how to fix it.
If you dont know how to fix the problem maybe you know some tool which does a simillar thing as this one.
Thanks in advance
I have fixed the issue I had so I wanted to provide the answer on how I did it so if anyone encounters this InterfaceErrror, maybe you can try this.
Basically Django's default database is SQLite3 but this app requires PostgreSQL which I somehow overlooked, so if you are encountering the "Error binding Parameter 5", maybe you can try changing your database and hopefully that will fix the error as it did for me.

Downloadlink for a file dynamically created by a Trac- Wikimacro

I've been given the task to write a plugin for Trac.
It should provide burndown data for the ticketcount and estimations filed in the issue tracking system.
The user writes his request as a wikimacro and is provided a link/ button for downloading the burndown as a csv-file, output as a chart is also planned, but has lower priority.
I've got a working solution for processing the data but I'm left with the following problem.
My Question
How can I provide a downloadlink/- button on the Wikipage for a file which is dynamically created by the users request?
I've seen some attempts to send files in the trac source itself and other plugins, but since I'm new to web programming that doesn't really help.
Update1
I've been trying to solve the problem the way Felix suggested, which opened up a new problem for me.
This (stupid) example should demonstrate my problem.
My Macro generates the following URL and adds it as a link to the wikipage.
//http://servername.com/projectname/wiki/page_name?teddy=bear
But the RequestHandler doesn't react, even if the condition returns true.
Edit: This piece of code now shows the working version for the example.
New URL:
#example url
#http://127.0.0.1:8000/prove/files/new
class CustomRequestHandlerModule(Component):
implements(IRequestHandler)
def match_request(self,req):
#old, not working
#return "teddy=bear"== str(req.path_info).split('?')[1]
#new
accept="/files/new"== str(req.path_info)
return accept
def process_request(self,req):
csvfile = self.create_csv()
req.send_response(200)
req.send_header('Content-Type', 'text/csv')
req.send_header('Content-length', len(csvfile))
req.send_header('Content-Disposition','filename=lala.csv')
req.end_headers()
req.write(csvfile)
raise RequestDone
Update2
Inserting loggingstatements shows match_request never gets called.
What am I doing wrong? (Yes, the create_csv() exists already)
Update 3 Thx, for helping =)
If match_request isn't getting called, then process_request never has a chance to execute. Assuming that there's nothing wrong with your plugin that's preventing Trac from loading it correctly, what's probably happening is that another handler is matching the URL before your version of match_request gets called. Try increasing your log level to "Debug" and see if it provides enough information to tell who is processing that request.
Another option is to create a custom "namespace" for your auto-generated files. Try replacing 'wiki' in the generated URLs with something like 'files'. This should prevent any of the built-in handlers from handling the request before your plugin's match_request method gets called.
Basically you need to write your own IRequestHandler which handles a specific URL and returns your dynamically created data. Afterwards you macro should return a url which is configured for your request handler.

Trouble getting code parameter on facebook oauth callback

I'm writing a Django app requesting permission to post on facebook.
I can access authorization and callback, but I can't get the parameter 'code' that facebook needs to continue with oauth.
def connect_fb(request):
return redirect("https://graph.facebook.com/oauth/authorize?"
+"client_id=MY_ID&"
+"redirect_uri=MY_URL"
+"&type=user_agent&display=popup&scope=publish_stream")
def callback_facebook(request):
code=request.REQUEST.get("code")
What's the right way to get 'code' so I can continue the oauth process?
I tried several things but I keep getting None instead of a code.
Thanks
I've used django-facebook-oauth in the past, but if you really want to roll your own solution then I'd suggest just looking through their source.
From just glancing through it, the only thing I can see you doing differently is the
&type=user_agent&display=popup
in the URL. The app I linked you to doesn't appear to do that as far as I can tell.
The problem comes from type=user_agent that is used in javascript authentication, and not here.
Removing it allows to get code as above.

Categories