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

ERROR: type Response has no field data #31

Closed
aguang opened this issue Feb 25, 2020 · 6 comments · Fixed by #33
Closed

ERROR: type Response has no field data #31

aguang opened this issue Feb 25, 2020 · 6 comments · Fixed by #33

Comments

@aguang
Copy link
Contributor

aguang commented Feb 25, 2020

This template is rather extensive. Fill out all that you can, if are a new contributor or you're unsure about any section, leave it unchanged and a reviewer will help you 😄. This template is simply a tool to help everyone remember the BioJulia guidelines, if you feel anything in this template is not relevant, simply delete it.

I am trying to use EUtils to query NCBI's Entrez databases. When I run the example in the documentation, it does not produce the expected behavior:

res = efetch(db="nuccore", id="NM_001126.3", retmode="xml")
doc = parsexml(res.data)

Expected Behavior

Expected behavior is for parsexml to work and provide me with an object I can extract specific fields from.

Current Behavior

Instead, I get:

julia> doc = parsexml(res.data)
ERROR: type Response has no field data
Stacktrace:
 [1] getproperty(::Any, ::Symbol) at ./sysimg.jl:18
 [2] top-level scope at none:0

Steps to Reproduce (for bugs)

res = efetch(db="nuccore", id="NM_001126.3", retmode="xml")
doc = parsexml(res.data)

Context

I want to be able to extract a specific field from querying an Entrez database (in my case IDs from the IdList of an SRA query).

Your Environment

  • Package Version used:
    Status
  [a0d4ced5] + BioServices v0.3.2
  [8f5d6c58] + EzXML v1.0.0
  [ddb6d928] + YAML v0.3.2
  • Julia Version used:
julia> versioninfo()
Julia Version 1.1.0
Commit 80516ca202 (2019-01-21 21:24 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin14.5.0)
  CPU: Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
  • Operating System and version (desktop or mobile): macOS Mojave
@kescobo
Copy link
Member

kescobo commented Feb 26, 2020

I can reproduce on julia 1.4. Offending section of the docs is here. If you look at the type of res, it comes from the HTTP.jl package. I'm guessing they changed their API.

julia> typeof(res)
HTTP.Messages.Response

julia> res.data
ERROR: type Response has no field data
Stacktrace:
 [1] getproperty(::HTTP.Messages.Response, ::Symbol) at ./Base.jl:33

It looks like you can get similar information by using instead res.body (or String(res.body)) if you want a string instead of bytes). It certainly looks like XML, but I tried parsexml on it and got:

julia> parsexml(res.body)
EzXML.Document(EzXML.Node(<DOCUMENT_NODE@0xError showing value of type EzXML.Document:
ERROR: MethodError: no method matching zero(::Ptr{EzXML._Node})
Closest candidates are:
  zero(::Type{Missing}) at missing.jl:103
  zero(::Type{LibGit2.GitHash}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/LibGit2/src/oid.jl:220
  zero(::Type{Pkg.Resolve.VersionWeight}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/Pkg/src/Resolve/versionweights.jl:15

I'm afraid that's the end of my ability to debug, but the short version is I don't think this is a problem with BioServices code, it seems to be an issue with EzMXL (and maybe not a bug, just I don't know the right way to do the parsing). Definitely a documentation issue here though - once we get this sorted, it would be a great opportunity for a PR :-)

@aguang
Copy link
Contributor Author

aguang commented Feb 26, 2020

Ah, I should've responded earlier! I found the solution, it is done the right way in the tests, the problem was that the documentation was not updated. Correct way is to use parse_xml(String(res.body)) on the result instead.

    @testset "esearch" begin
        res = esearch(db="pubmed", term="""(Asthma[MeSH Major Topic]) AND
                                        ("1/1/2018"[Date - Publication] :
                                        "3000"[Date - Publication])""")
        @test res.status == 200
        @test startswith(Dict(res.headers)["Content-Type"], "text/xml")
        body = parse_xml(String(res.body))
        @test isa(body, XMLDict.XMLDictElement)
        @test first(body)[1] != "ERROR"
    end

I will make a PR for the docs when I get a chance.

@kescobo
Copy link
Member

kescobo commented Feb 26, 2020

That's great, thanks! We should really get doctests set up too to avoid things like this (not saying you need to worry about that for your PR 😆 ).

What's the difference between parsexml and parse_xml?

@aguang
Copy link
Contributor Author

aguang commented Feb 26, 2020

parsexml is a function in EZXml and parse_xml is a function in XMLDict. They both work on String(res.body). I'll include examples for both in the docs.

aguang added a commit to aguang/BioServices.jl that referenced this issue Mar 4, 2020
@aguang aguang mentioned this issue Mar 4, 2020
11 tasks
@aguang
Copy link
Contributor Author

aguang commented Mar 4, 2020

Just an update to say that I added some additional comments about res.body and XMLDict and LightXML, but that the main issue of the docs using res.data and res.body appeared to have already been fixed in prior PR #28. However it failed Travis checks. The error appears to be with deploying the docs:

Initialized empty Git repository in /tmp/jl_XoAsl5/.git/
Warning: Permanently added the RSA host key for IP address '140.82.114.4' to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
┌ Error: Git failed to fetch [email protected]:BioJulia/BioServices.jl.git
│ This can be caused by a DOCUMENTER_KEY variable that is not correctly set up.
│ Make sure that the environment variable is properly set up as a Base64-encoded string
│ of the SSH private key. You may need to re-generate the keys with DocumenterTools.
└ @ Documenter ~/.julia/packages/Documenter/IGqbY/src/Documenter.jl:692
ERROR: LoadError: failed process: Process(`git fetch upstream`, ProcessExited(128)) [128]
The command "julia --project --color=yes docs/make.jl" exited with 1.

@BioTurboNick
Copy link
Contributor

Just ran into this issue. :-)

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

Successfully merging a pull request may close this issue.

3 participants