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

Noob question: "function X does not accept keyword arguments" error #80

Closed
digeratus opened this issue Jan 11, 2020 · 2 comments
Closed

Comments

@digeratus
Copy link

Hi @tanmaykm and rest of contributors,

Julia noob here! Trying to create a prototype based on your example. Only difference is that I'd like to have a function that adds to an existing array InfoncastSoundFiles.

I get a "function does not accept keyword arguments" error from APIResponder if I'm understanding the error stack correctly. I believe I'm not configuring the create_responder function properly, but it could just be a syntax error elsewhere. Please advise.

Thanks,
Jose

Take a look at my srvr.jl and httpsrvr.jl:

using Dates
using JuliaWebAPI

mutable struct SoundFile
    title::String
    creator::String
    date::String
    tags::Array
    URL::String
end

#Let's see how this wwould work if this is not a const
#const InfoncastSoundFiles = SoundFile[
const InfoncastSoundFiles = SoundFile[
  SoundFile("Fur Elise", "Ludwig Beethoven","12202019",["mp3","song", "music"],"https://URL Here"),
  SoundFile("Fidelio", "Ludwig Beethoven","11032011",["song", "dance"],"https://URL Here"),
  SoundFile("Missa Solemnis", "Ludwig Beethoven","03102019",["mp3", "song"], "https://URL Here")
]


function listSoundFiles()
  return InfoncastSoundFiles
end

function updateSoundFiles(InfoncastSoundFiles, title1, author, date1, tag1, url1)
    a = SoundFile(title1,author,date1,tag1,url1);
    #push!(InfoncastSoundFiles, a);
    append!(InfoncastSoundFiles, a);
    #print(InfoncastSoundFiles);
end


process(
    JuliaWebAPI.create_responder([
        (listSoundFiles, true),
        (updateSoundFiles, false)
    ], "tcp://127.0.0.1:9999", true, "")
)

httpsrvr.jl looks like this:

using JuliaWebAPI   #Load package

#Create the ZMQ client that talks to the ZMQ listener above
const apiclnt = APIInvoker("tcp://127.0.0.1:9999");

#Starts the HTTP server in current process
run_http(apiclnt, 8888)

As you can see, there's really not much that's different from the original example. Unfortunately, my lack of experience reading Julia code didn't allow me to decipher the options for JuliaWebAPI.create_responder to be able to configure it properly, which I think is the problem.

I would very much appreciate any help on this. As a matter of fact, I'll make a pull request to add it as one of the examples in the repo if you think it's worthwhile.

Thanks again.

@digeratus
Copy link
Author

Don't pay any attention to this. I asked on the Discord forum and got an answer. My function signature had errors In it.

It should look like this:

function updateSoundFiles( ; title1=title1, author1=author1, date1=date1, tag1=tag1, url1=url1)
	push!(InfoncastSoundFiles,SoundFile(title1,author1,date1,[tag1],url1))
end

and for some reason testing this via curl results in issues, but with a properly formatted URL it works.

http://localhost:8888/updateSoundFiles?title1=Concerto&author1=Beethoven&date1=01102020&tag1=classical&url1=https://duckduckgo.com

I'm still on the hook for adding this as an example if you'd like for others to learn from, perhaps noobs like me ;)

Thanks

@tanmaykm
Copy link
Member

Good to know that you were able to find a solution. I shall close this issue.

The README.md already has an example illustrating the use of keyword arguments. The only difference I see is your usage has only keyword arguments and no positional arguments. Is that what you want to add an example of? Please feel free to send in a PR with more examples!

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

No branches or pull requests

2 participants