ipython / ipython/ipython

display.Video function seems broken when passed `filename` argument

Open
#12,180 3 comments 0 reactions 1 assignee Claimed by @fperez View on GitHub
Dominant language
Python
Stars
16.8k
Forks
4.5k
Avg merge
1d 2h
Merged PRs (30d)
6

Description

Calling (assuming the file `animation.m4v` exists locally) `Video("animation.m4v")` works just fine:

![image](https://user-images.githubusercontent.com/57394/76286463-7f935a80-625f-11ea-8a93-8d5e34ee1504.png)

but if I try to pass either explicitly the `filename` argument or the `data` one, as per the docs, I get errors. This for `filename`:

```
Video(filename="animation.m4v")

---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
in
----> 1 Video(filename="animation.m4v")

~/local/conda/lib/python3.7/site-packages/IPython/core/display.py in __init__(self, data, url, filename, embed, mimetype, width, height)
1362 url = data
1363 data = None
-> 1364 elif os.path.exists(data):
1365 filename = data
1366 data = None

~/local/conda/lib/python3.7/genericpath.py in exists(path)
17 """Test whether a path exists. Returns False for broken symbolic links"""
18 try:
---> 19 os.stat(path)
20 except OSError:
21 return False

TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType
```

and this for `data` (granted, I'm not sure if I should be doing some unicode handling here, but the docstring says bytes OR strings are OK, so I assumed this was fine:

```
Video(data=open("animation.m4v", "rb").read())

---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in
----> 1 Video(data=open("animation.m4v", "rb").read())

~/local/conda/lib/python3.7/site-packages/IPython/core/display.py in __init__(self, data, url, filename, embed, mimetype, width, height)
1362 url = data
1363 data = None
-> 1364 elif os.path.exists(data):
1365 filename = data
1366 data = None

~/local/conda/lib/python3.7/genericpath.py in exists(path)
17 """Test whether a path exists. Returns False for broken symbolic links"""
18 try:
---> 19 os.stat(path)
20 except OSError:
21 return False

ValueError: stat: embedded null character in path
```

@Carreau, happy to try to fix this so I have a bit of code in IPython after so many years :)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.