dmjio / hackernews

:newspaper: HackerNews API
http://hackage.haskell.org/package/hackernews
MIT License
40 stars 9 forks source link

ConnectionError #16

Closed latkins closed 8 years ago

latkins commented 9 years ago

Not sure what I might be doing wrong, but:

main :: IO ()
main = do
  r <- hackerNews (getItem $ ItemId 10575270)
  print r

results in:

Left ConnectionError

Any idea why this might be?

zudov commented 9 years ago

Most likely something is actually wrong with your connection.

We throw away all information about the problem when the request fails. https://github.com/dmjio/hackernews/blob/master/src/Web/HackerNews/Client.hs#L133

This means that you would have to figure out what's wrong with connection yourself. To do that you can use curl or run something like withOpenSSL $ openConnectionSSL ctx "hacker-news.firebaseio.com" 443 from ghci and see what exception it throws.

I think we should provide information about what went wrong rather than just giving ConnectionError, but it might be not simple with ghcjs (unless we define our own error description)

latkins commented 9 years ago

Hmm, so running

ctx <- baselineContextSSL
x <- withOpenSSL $ openConnectionSSL ctx "hacker-news.firebaseio.com" 443
print x

gives Segmentation fault: 11. This seems to happen before the ctx <- baselineContextSSL. Guess I will try and work out what is going on!

On Mon, 16 Nov 2015 at 18:03 Konstantin Zudov notifications@github.com wrote:

Most likely something is actually wrong with your connection.

We throw away all information about the problem when the request fails. https://github.com/dmjio/hackernews/blob/master/src/Web/HackerNews/Client.hs#L133

This means that you would have to figure out what's wrong with connection yourself. To do that you can run something like withOpenSSL $ openConnectionSSL ctx "hacker-news.firebaseio.com" 443 from ghci and see what exception it throws.

I think we should provide information about what went wrong rather than just giving ConnectionError, but it might be not simple with ghcjs (unless we define our own error description)

— Reply to this email directly or view it on GitHub https://github.com/dmjio/hackernews/issues/16#issuecomment-157120959.

zudov commented 9 years ago

Looks like a problem with some native dependencies

latkins commented 9 years ago

So actually it looks I just had to initialise openssl.

main = withOpenSSL $ do
  ctx <- baselineContextSSL
  x <- withOpenSSL $ openConnectionSSL ctx "hacker-news.firebaseio.com" 443
  print x

This gives:

Host: hacker-news.firebaseio.com

Which would suggest something else is happening.

latkins commented 9 years ago

Scratch that, the original function is now working. How very odd.

zudov commented 9 years ago

Which would suggest something else is happening.

I guess it means that the connection was established successfully

latkins commented 9 years ago

Okay, I understand now. It seems that the failed attempts were all on the Ask sub board. Individual comments, stories etc, all work perfectly. Is this as it should be (e.g. 10027102 fails with getItem) ?

dmjio commented 9 years ago

@latkins, yea, if you don't use withOpenSSL the HsOpenSSL package will segfault :smile:

latkins commented 9 years ago

Just to clarify:

main :: IO ()
main = do
  a <- hackerNews (getItem $ ItemId 10572982)
  print a

  b <- hackerNews (getItem $ ItemId 10575270)
  print b

returns:

Left NotFound
Right (ItemStory (Story {storyBy = "kevinchen", storyId = StoryId 10575270, storyKids = [10576385,10575656,10576293,10576021,10575794,10575711,10575512], storyScore = 80, storyTime = 2015-11-16 16:22:24 UTC, storyTitle = "Intel 4004 mask design released, converted to SVG file", storyType = "story", storyUrl = "http://www.4004.com/2015-news.html", storyDeleted = False, storyDead = False}))
dmjio commented 9 years ago

@latkins cross check 10572982 w/ a different hacker news API. If it's the same issue, it's not on our end.

latkins commented 9 years ago

@dmjio:

Using the python firebase library to get 10572982 gives:

{u'by': u'sharmi',
 u'descendants': 7,
 u'id': 10572982,
 u'kids': [10573135, 10575020, 10574117, 10573862],
 u'score': 18,
 u'text': u'Hi,\n   I am using Introduction to Probability by Joe Blitzstein and Jessica Hwang to learn probability by self study but I would like to have an additional book for problems practice. Can you suggest one that has solutions available for students?  It would be nice if it is free but it is ok otherwise.',
 u'time': 1447655872,
 u'title': u'Ask HN: What is the best book to learn probability through self study?',
 u'type': u'story'}
dmjio commented 8 years ago

@latkins this is fixed in 1.0, on hackage