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

AttributeError: 'file' object has no attribute 'buffer' #39

Closed
nodecentral opened this issue Jan 30, 2021 · 4 comments
Closed

AttributeError: 'file' object has no attribute 'buffer' #39

nodecentral opened this issue Jan 30, 2021 · 4 comments
Labels
bug Something isn't working

Comments

@nodecentral
Copy link

Hi

I wonder if someone can help, as I can send the following command fine when logged on locally,

graph shared/feed.csv -y 9,10 --ylabel Temp --title CabinTemp --figsize 1600x1000 --output shared/zzzz07.png

But when I try to send it remotely from another machine using this, (which works for other commands)

ssh -i /etc/dropbear/dropbear_rsa_host_key pi@192.168.1.37 graph shared/feed.csv -y 9,10 --ylabel Temp --title CabinTemp --figsize 1600x1000 --output shared/zzzz07.png

I get this error message

Traceback (most recent call last):
  File "/usr/local/bin/graph", line 11, in <module>
    sys.exit(main.main())
  File "/usr/local/lib/python2.7/dist-packages/graph_cli/main.py", line 10, in main
    graphs = get_graph_defs(args)
  File "/usr/local/lib/python2.7/dist-packages/graph_cli/graph.py", line 171, in get_graph_defs
    graphs, globals = read_chain(args)
  File "/usr/local/lib/python2.7/dist-packages/graph_cli/graph.py", line 194, in read_chain
    data = stdin.buffer.read()
AttributeError: 'file' object has no attribute 'buffer'

Does anyone have any ideas what the issue might be ?

@mcastorina
Copy link
Owner

Thanks for opening an issue!

A few problems I see in the relevant code snippet:

if stdin is not None and not stdin.isatty() and args.file != stdin:
    data = stdin.buffer.read()
  1. stdin.buffer is Python3, so that explains the AttributeError in Python2
  2. The if statement isn't detecting there is nothing to read from stdin when used with ssh

A workaround would be to use ssh -t to allocate a pseudo-terminal (making stdin.isatty() == True).

@mcastorina mcastorina added the bug Something isn't working label Jan 30, 2021
@nodecentral
Copy link
Author

Hi @mcastorina

Thanks, however adding -t only returns a different error.

ssh -i -t /etc/dropbear/dropbear_rsa_host_key pi@192.168.102.37 graph shared/feed.csv -y 9,10 --ylabel Temp --title CabinTemp --figsize 1600x1000 --output shared/zzzz08.png

ssh: Failed loading keyfile '-t'


ssh: Exited: Bad hostname

What confuses me is that I’m ultimately running the same piece of graph_cli code on the same machine - it’s just that one way I’m doing directly (into the device’s command line), the other way I’m sending it from another machine ?

@mcastorina
Copy link
Owner

Yeah, I can see how that's confusing. graph-cli attempts to detect if data is being piped into it or not for the chaining feature. So when you run it from an interactive session, isatty() is True. When you execute from a non-interactive ssh command, isatty() is False. That's why it is happening.

The same would happen if you run echo | graph ....

The full ssh command you should try is:

ssh -t -i /etc/dropbear/dropbear_rsa_host_key pi@192.168.102.37 'graph shared/feed.csv -y 9,10 --ylabel Temp --title CabinTemp --figsize 1600x1000 --output shared/zzzz08.png'

@nodecentral
Copy link
Author

That looks to have done it ! - Thanks so much, see confirmation below.

root@mymachine:/# ssh -t -i /etc/dropbear/dropbear_rsa_host_key pi@192.168.102.37 'graph shared/feed.csv -y 9,10 --ylabel Temp --title CabinTemp --figsize 1600x1000 --output shared/zzzz08.png'

/usr/local/lib/python2.7/dist-packages/pandas/plotting/_converter.py:129: FutureWarning: Using an implicitly registered datetime converter for a matplotlib plotting method. The converter was registered by pandas on import. Future versions of pandas will require you to explicitly register matplotlib converters.

To register the converters:
        >>> from pandas.plotting import register_matplotlib_converters
        >>> register_matplotlib_converters()
  warnings.warn(msg, FutureWarning)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants