Http Failure 0 []

126 views
Skip to first unread message

Max Goldstein

unread,
Aug 30, 2013, 2:53:33 PM8/30/13
to elm-d...@googlegroups.com
I can't get Http to connect. This program

import Http

url = constant "http://www.google.com"
main = lift asText <| Http.sendGet url

prints

Failure 0 []

and my debugger says the request was cancelled. That's both locally and on the web editor. This could be an Elm issue, or it could be a firewall issue, although I don't have anything particularly restrictive set up, or it could be a me using the API wrong issue.

Help?

Max

John Mayer (gmail)

unread,
Aug 30, 2013, 3:19:03 PM8/30/13
to elm-d...@googlegroups.com
Do you have an error in console output? F12 in most browsers to bring up those tools.

Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Max Goldstein

unread,
Aug 30, 2013, 3:26:06 PM8/30/13
to elm-d...@googlegroups.com
I'm guessing you can't reproduce the issue?

Yes, there is:

XMLHttpRequest cannot load http://www.google.com/. Origin http://localhost:8000 is not allowed by Access-Control-Allow-Origin.

Hmm.

Max Goldstein

unread,
Aug 30, 2013, 6:38:26 PM8/30/13
to elm-d...@googlegroups.com
I'm on Chrome 29 on Mac OS X Mountain Lion. Haven't been able to find a solution that doesn't require server-side modification, which of course is no good in the general case. It has something to do with cross-site-scripting protection. Help?

Evan Czaplicki

unread,
Aug 30, 2013, 6:51:41 PM8/30/13
to elm-d...@googlegroups.com
Yeah, this is a cross-site scripting issue. This security is built-in to browsers and the AJAX protocols, and some sites just don't let you work around it (which is usually good). I've observed this with the Google home page before, but it's possible to find sites that are not so strict. Do you need Google in particular?

Evan Czaplicki

unread,
Aug 30, 2013, 6:52:34 PM8/30/13
to elm-d...@googlegroups.com
I think there are some crazy flags in Chrome, like "turn off all security measures", but probably it's best to not do this :P

Max Goldstein

unread,
Aug 30, 2013, 6:56:18 PM8/30/13
to elm-d...@googlegroups.com
No, I don't need google specifically. I encountered it trying to get a page from a university-hosted page (http://www.eecs.tufts.edu/~mgolds07/nark/data.json), of which I control the content but not the HTTP server. When I saw it on google too I assumed it was site-invariant but that may have been premature.

My best workaround is probably to take the contents of that page (which is static) and include them in a string literal. Even with triple quotes I couldn't get it to work.

John Mayer (gmail)

unread,
Aug 30, 2013, 7:20:44 PM8/30/13
to elm-d...@googlegroups.com
I think this will only work for paths, not arbitrary urls.

We should get jsonp though!

Sent from my iPhone

Evan Czaplicki

unread,
Aug 30, 2013, 8:51:42 PM8/30/13
to elm-d...@googlegroups.com
I've seen it matter if you are reading the html file from disk into browser or using elm-server to "host" them. Not sure if that helps in this case. I need to make the JSON library better in any case, so if there are extra things to do for this kind of problem, let me know and I'll add them to the list of concerns.

Max Goldstein

unread,
Aug 30, 2013, 9:13:28 PM8/30/13
to elm-d...@googlegroups.com
Sorry John, that's not parsing for me. What is the "this" you refer to? Literal JSON strings, the problem I'm encountering, or something else?

JSONP looks like an option based on its Wiki page, but I'm afraid it's not really my forte.

Evan, I can try hosting locally and see if that gets me unblocked. Oh look, elm-server hosts non-elm files too. Yup, that seems to work.

It's not the JSON library, it's the HTTP library. From the non-technical end-user perspective, it's not working, and should be fixed. Timeframe isn't immediate.

In the course of the project this ties into I've thought about what sort of JSON functions would be nice to have, but haven't come up with anything definitive. Hazy ideas include a way to recursively turn JsonValues into native types and Json.Object to record conversion. I did find myself writing these helper functions, though I can't promise they're API worthy:

numJSON k d = findWithDefault (Json.Number 0 ) k d |> (\(Json.Number n)->n)        
strJSON k d = findWithDefault (Json.String []) k d |> (\(Json.String s)->s) 

Part of the problem is that I know the field will be present, but the compiler doesn't, so instead of percolating a Maybe upwards (basically reinventing exceptions but worse) I give it a default that should never be used.

Evan Czaplicki

unread,
Aug 30, 2013, 9:59:10 PM8/30/13
to elm-d...@googlegroups.com
I think there are functions just like the ones you created, but they are commented out because I did not feel good about them :) This is actually coming up on reddit at the moment. I am sort of into the idea in the edit there.

It seems like something like F#'s type providers is the dream here. More thought needs to go into this topic.
Reply all
Reply to author
Forward
0 new messages