Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Using paramiko and odoo 9

Diego Calzadilla
on 12/29/15, 5:36 PM 352 views

I'm developing a module that uploads specific files via ssh to specific server based on customer creation:


class ResPartner(models.Model):
    _name = 'res.partner'
    _inherit = 'res.partner'

    def create(self, vals):
        if vals:
            testfile=open("/tmp/diegotexting.txt", "w")
            testfile.write("Hi, testing odoo 9 ")
            ssh = paramiko.SSHClient() 
            ssh.connect("foo.org", username="foo", password="foo")
            sftp = ssh.open_sftp()
            sftp.put("/tmp/diegotexting.txt", "/tmp/diegotexting.txt")
        return super(ResPartner, self).create(vals)

It does upload the file in server "foo.org", the problem is that when I open it, it's blank.

I have tested the upload script outside of odoo enviroment and works well(it doesn't show a blank file).

Does anyone know what could be wrong?

On 12/30/15, 7:50 AM

@Diego, the problem is probably that the file is still open when you start the upload. The open method will create an empty file, but the write method will only cache the string you want to write to the file. To make sure all the cached information are written to the file you can either use the flush or even better the close method.

testfile=open("/tmp/diegotexting.txt", "w")
testfile.write("Hi, testing odoo 9 ")

Best regards


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


Asked: 12/29/15, 5:36 PM
Seen: 352 times
Last updated: 12/30/15, 10:55 AM