nicolewhite / cycli

A Command Line Interface for Neo4j's Cypher.
MIT License
272 stars 25 forks source link

Using -f is opening the file in binary mode #52

Open mscaldas2012 opened 7 years ago

mscaldas2012 commented 7 years ago

Hi, I tried running a series of queries saved on a file through cycle , but it's complaining that the file is binary? I was using -f flag. After many trials, i did with --filename and it worked fine !

aren't those two flags have the same behavior?

nicolewhite commented 7 years ago

Hmm what OS are you on?

rajfal commented 6 years ago

Hi Nicole, I have enjoyed the cypher side of Cycli

However, I am experiencing exactly the same problem as above but with both -f and --filename flags Can't get cypher queries processed from a file My OS is Ubuntu 5.4.0-6ubuntu1~16.04.5

TypeError: a bytes-like object is required, not 'str'

THank you for your help

nicolewhite commented 6 years ago

What version of Python are you on?

rajfal commented 6 years ago

Python 3.6.0 :: Anaconda 4.3.0 (64-bit)

victoriastuart commented 6 years ago

Arch Linux x86_64; Python 2.7; Python 3.5; Cycli 0.7.6

I also just encountered this issue with Cycli v.0.7.6 (pip install ...) operating in a Python 3.5 venv.

`TypeError: a bytes-like object is required, not 'str'`
(py35) [victoria@victoria ~]$ cycli -P 7474 -u victoria -p <my_password> -f glycolysis2.cypher

Traceback (most recent call last):
  File "/home/victoria/anaconda2/envs/py35/bin/cycli", line 11, in <module>
    sys.exit(run())
  File "/home/victoria/anaconda2/envs/py35/lib/python3.5/site-packages/click/core.py", line 664, in __call__
    return self.main(*args, **kwargs)
  File "/home/victoria/anaconda2/envs/py35/lib/python3.5/site-packages/click/core.py", line 644, in main
    rv = self.invoke(ctx)
  File "/home/victoria/anaconda2/envs/py35/lib/python3.5/site-packages/click/core.py", line 837, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/victoria/anaconda2/envs/py35/lib/python3.5/site-packages/click/core.py", line 464, in invoke
    return callback(*args, **kwargs)
  File "/home/victoria/anaconda2/envs/py35/lib/python3.5/site-packages/cycli/main.py", line 284, in run
    cycli.run()
  File "/home/victoria/anaconda2/envs/py35/lib/python3.5/site-packages/cycli/main.py", line 72, in run
    queries = queries.split(";")[:-1]

TypeError: a bytes-like object is required, not 'str'

(py35) [victoria@victoria ~]$
danodonovan commented 6 years ago

@victoriastuart I believe this PR https://github.com/nicolewhite/cycli/pull/60 should correct that issue (it uses io to safely handle the file opening for python 2 and 3).

victoriastuart commented 6 years ago

@nicolewhite, @danodonovan: this is great, thank you!!

For referencing this issue, here is how I updated my Cycli install (git clone this repo | make | make install | pip uninstall / install cycli | test execute cypher file):

[victoria@victoria apps]$ pwd
    /mnt/Vancouver/apps

[victoria@victoria apps]$ git clone https://github.com/nicolewhite/cycli

[victoria@victoria apps]$ cd cycli

## Update repo, after Nicole's 2018-04-05 merge commit
## https://github.com/nicolewhite/cycli/pull/60

[victoria@victoria cycli]$ git pull
    ...

[victoria@victoria cycli]$ p3                                                                                                              
    [Anaconda Python 3.5 venv (source activate py35)]

[victoria@victoria cycli]$ p3
    [Anaconda Python 3.5 venv (source activate py35)]

(py35) [victoria@victoria cycli]$ pwd
  /mnt/Vancouver/apps/cycli

(py35) [victoria@victoria cycli]$ pip uninstall cycli
    Uninstalling cycli-0.7.6:
    ...

(py35) [victoria@victoria cycli]$ make
    ...

(py35) [victoria@victoria cycli]$ py.test tests
    ...
    ================= 82 passed in 0.33 seconds ================================

(py35) [victoria@victoria cycli]$ make clean
    rm -rf build dist cycli.egg-info

(py35) [victoria@victoria cycli]$ pip install cycli
    ...

(py35) [victoria@victoria cycli]$ cycli -P 7474 -u victoria -p <password_obfuscated_here>
 ______     __  __     ______     __         __    
/\  ___\   /\ \_\ \   /\  ___\   /\ \       /\ \   
\ \ \____  \ \____ \  \ \ \____  \ \ \____  \ \ \  
 \ \_____\  \/\_____\  \ \_____\  \ \_____\  \ \_\ 
  \/_____/   \/_____/   \/_____/   \/_____/   \/_/ 
Cycli version: 0.7.6
Neo4j version: 3.3.4
Bug reports: https://github.com/nicolewhite/cycli/issues

> quit
Goodbye!

(py35) [victoria@victoria cycli]$ cycli -P 7474 -u victoria -p <password_obfuscated_here> -f /mnt/Vancouver/Programming/data/metabolism/glycolysis.cypher

> LOAD CSV WITH HEADERS FROM "file:/mnt/Vancouver/Programming/data/metabolism/pg2neo4j/glycolysis_bioentities.csv" AS row
MERGE (n:Glycolysis {name:row.name})
  // RETURN n, labels(n), n.name;
270 ms
...

(py35) [victoria@victoria cycli]$
fraewn commented 5 years ago

Hi there, I'm still having the same issue under windows with neo4j 3.5.5. did neither work with -f nor with --filename. i was trying to open a cyp file Also btw needed to change/add an encoding after this error occured to get the program to work at all: SyntaxError: Non-UTF-8 code starting with '\xfc' in file cycli-script.py (after entering "cycli -u ") great program tho! thx