Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3 AGI: write() argument must be str, not bytes #40

Open
marrold opened this issue Jul 20, 2018 · 2 comments
Open

Python3 AGI: write() argument must be str, not bytes #40

marrold opened this issue Jul 20, 2018 · 2 comments

Comments

@marrold
Copy link

marrold commented Jul 20, 2018

When using asterisk.agi with python 3.5, Asterisk 14 and Debian, I get the following exception

write() argument must be str, not bytes

I noticed if I replace lines 166-169:

https://github.com/rdegges/pyst2/blob/bd61a408412aef6119c750352ea2f38a71f6d596/asterisk/agi.py#L166-L169

With the following:

self.stdout.write(command)

It works fine.

Does anyone have any ideas how to fix this?

Thanks

@evilscientress
Copy link
Contributor

I have the same error. Removing the if clause in lines 166-169 and replacing it with self.stdout.write(command) seams like the correct fix for me.

I had this working with Python 3.4, and TBH I don't know why those lines ever worked in the first place, because in no version of Python 3 sys.stdout.write() accepted bytes, unless you call sys.stdout.detach() first.

Refs:

@angelelena
Copy link

angelelena commented Jul 23, 2023

With debian 11 and python 3.9, may be:

def send_command(self, command, *args):
        """Send a command to Asterisk"""
        command = command.strip()
        command = '%s %s' % (command, ' '.join(map(str, args)))
        command = command.strip()
        if command[-1] != '\n':
            command += '\n'
        self.stderr.write('    COMMAND: %s' % command)
        self.stdout.write(command.encode('utf8'))
        self.stdout.flush()

Basically:

self.stdout.write(command.encode('utf8'))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants