# KeyError: \_\_array\_interface\_\_ not found when using PyCall

**URL:** <https://discourse.julialang.org/t/keyerror---array-interface---not-found-when-using-pycall/1189>\
**Category:** General Usage\
**Tags:** pycall\
**Created:** [December 28, 2016, 8:09pm UTC](https://discourse.julialang.org/t/keyerror---array-interface---not-found-when-using-pycall/1189 "2016-12-28T20:09:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bluesmoon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bluesmoon/32/327_2.png) [@bluesmoon](https://discourse.julialang.org/u/bluesmoon)\
**Post date:** [December 28, 2016, 8:09pm UTC](https://discourse.julialang.org/t/keyerror---array-interface---not-found-when-using-pycall/1189/1 "2016-12-28T20:09:31Z")

</div>

I’m using PyCall 1.7.1 in julia 0.4 to call out to a python 3.4 library, and there are cases when the library throws a `PyCall.PyError`. When I try to inspect the `: __class__ ` of this error, I get an error:

```
# ex is an exception of type `PyCall.PyError`
julia> fieldnames(ex)
[:msg,:T,:val,:traceback]

julia> keys(ex.val)
[: __bytes__ ,: __cause__ ,: __class__ ,: __context__ ,: __delattr__ ,: __dict__ ,: __dir__ ,: __doc__ ,: __eq__ ,: __format__ ,: __ge__ ,: __getattribute__ ,: __gt__ ,: __hash__ ,: __init__ ,: __le__ ,: __lt__ ,: __module__ ,: __ne__ ,: __new__ ,: __reduce__ ,: __reduce_ex__ ,: __repr__ ,: __setattr__ ,: __setstate__ ,: __sizeof__ ,: __str__ ,: __subclasshook__ ,: __suppress_context__ ,: __traceback__ ,: __unicode__ ,: __weakref__ ,:args,:default_errorhandler,:errno,:errorhandler_wrapper,:logger,:msg,:sfqid,:sqlstate,:with_traceback]

julia> pyclass = ex.val[: __class__]
ERROR: KeyError: __array_interface__ not found
 in getindex at /home/ubuntu/.julia/v0.4/PyCall/src/PyCall.jl:260
 in pysequence_query at /home/ubuntu/.julia/v0.4/PyCall/src/conversions.jl:729
 [inlined code] from /home/ubuntu/.julia/v0.4/PyCall/src/conversions.jl:745
 in pytype_query at /home/ubuntu/.julia/v0.4/PyCall/src/conversions.jl:774
 in convert at /home/ubuntu/.julia/v0.4/PyCall/src/conversions.jl:794
 in error_handler at /home/ubuntu/foo.jl:76

```

This doesn’t happen via the REPL, and only happens in code executing via a file, like my unit tests.

Does anyone know what the ` __array_interface__ not found` error means?

_Update_: I have these two lines:

```
    println(ex.val[: __class__])
    pyclass = ex.val[: __class__]

```

The first line works, the second line throws the error.

---

<div class="post-metadata">

**Author:** ![ihnorton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ihnorton/32/26_2.png) [@ihnorton](https://discourse.julialang.org/u/ihnorton)\
**Post date:** [December 28, 2016, 9:46pm UTC](https://discourse.julialang.org/t/keyerror---array-interface---not-found-when-using-pycall/1189/2 "2016-12-28T21:46:44Z")

</div>

> [@bluesmoon](#):
>
> Does anyone know what the **array\_interface** not found error means?

It means the PyCall auto-conversion machinery is trying to convert an object via the NumPy array interface, but that interface is not supported by the object.

I can’t reproduce this with the following simple attempt, so a reduced case might help (or at least specify what is the error type on the Python side, and the output of your `println`):

```julia
julia> global err

julia> try
         pyeval("1/0")
       catch err
       end

julia> typeof(err)
PyCall.PyError

julia> pyclass = err.val[: __class__]
PyObject <class 'ZeroDivisionError'>

```

(OSX, Julia 0.4.5, PyCall 1.7.2, Python 3.5),

---

<div class="post-metadata">

**Author:** ![bluesmoon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bluesmoon/32/327_2.png) [@bluesmoon](https://discourse.julialang.org/u/bluesmoon)\
**Post date:** [December 29, 2016, 3:54pm UTC](https://discourse.julialang.org/t/keyerror---array-interface---not-found-when-using-pycall/1189/3 "2016-12-29T15:54:22Z")

</div>

Thanks, this makes sense since I do not have NumPy installed on this box.

The library I’m using is python-snowflake-connector, which is a DBI connector to the Snowflake database, and the specific error is `snowflake.connector.ProgrammingError`.

I was able to work around the issue by calling `string()` on the error itself, and parsing out the error class name from there.

---

<div class="post-metadata">

**Author:** ![ihnorton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ihnorton/32/26_2.png) [@ihnorton](https://discourse.julialang.org/u/ihnorton)\
**Post date:** [December 29, 2016, 4:31pm UTC](https://discourse.julialang.org/t/keyerror---array-interface---not-found-when-using-pycall/1189/4 "2016-12-29T16:31:32Z")

</div>

This seems like a bug. PyCall shouldn’t attempt to convert via an  
unsupported interface. If you can make a reduced case, please open an issue  
on PyCall and ping me.

---

<div class="post-metadata">

**Author:** ![bluesmoon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bluesmoon/32/327_2.png) [@bluesmoon](https://discourse.julialang.org/u/bluesmoon)\
**Post date:** [December 29, 2016, 5:38pm UTC](https://discourse.julialang.org/t/keyerror---array-interface---not-found-when-using-pycall/1189/5 "2016-12-29T17:38:43Z")

</div>

Thanks, I’ll try, but it seems you might need snowflake credentials to try this out.

---

<div class="post-metadata">

**Author:** ![bluesmoon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bluesmoon/32/327_2.png) [@bluesmoon](https://discourse.julialang.org/u/bluesmoon)\
**Post date:** [December 29, 2016, 5:50pm UTC](https://discourse.julialang.org/t/keyerror---array-interface---not-found-when-using-pycall/1189/6 "2016-12-29T17:50:53Z")

</div>

Actually it seems to be fixed with PyCall 1.7.2.

I have filed a different bug though (#340) which is related and is still an issue in 1.7.2.

Thank you.
