2

Im trying to convert this curl request to HTTP-Conduit one:

curl -v https://api.sandbox.paypal.com/v1/identity/openidconnect/userinfo/?schema=openid -H "Content-Type:application/json" -H "Authorization:Bearer -AxLVv0fegyk-opT.2sG5JGQ3VNHUL08WpWkO3s7tVI"

My haskell code is :

{-# LANGUAGE OverloadedStrings #-}
import Network.HTTP.Conduit 
import Data.ByteString.Char8
import qualified Data.ByteString.Lazy as L
import Network.HTTP.Types.Header
import Network                (withSocketsDo)
import Control.Failure

import Network.HTTP.Types

getReq ::  Failure HttpException m => m Request
getReq = parseUrl "https://api.sandbox.paypal.com/v1/identity/openidconnect/userinfo/?schema=openid"

getRequestHeaders :: RequestHeaders
getRequestHeaders = [ ( "Content-Type" , "application/json")
                    , ( "Authorization" , "Bearer -AxLVv0fegyk-opT.2sG5JGQ3VNHUL08WpWkO3s7tVI")
                    ]


main :: IO ()
main = do
    req0 <- getReq
    let req = req0 { method = methodPost
                   , requestHeaders = getRequestHeaders
                   }
    res <- withManager $ httpLbs req
    L.putStrLn $ responseBody res

When running main getting this error :

*** Exception: TlsException (HandshakeFailed (Error_Packet_unexpected "Alert [(AlertLevel_Fatal,DecryptError)]" " expected: change cipher"))

Any help?

UPDATE:

Running

  cabal list --installed HTTP-Conduit
  cabal list --installed tls

Got me this response

 * http-conduit
    Synopsis: HTTP client package with conduit interface and HTTPS support.
    Default available version: 2.0.0.4
    Installed versions: 1.9.4.5
    Homepage: http://www.yesodweb.com/book/http-conduit
    License:  BSD3


* http-client-tls
    Synopsis: http-client backend using the connection package and tls library
    Default available version: 0.2.0.3
    Installed versions: 0.2.0.3
    Homepage: https://github.com/snoyberg/http-client
    License:  MIT

* tls
    Synopsis: TLS/SSL protocol native implementation (Server and Client)
    Default available version: 1.2.2
    Installed versions: 1.1.5
    Homepage: http://github.com/vincenthz/hs-tls
    License:  BSD3

* tls-extra
    Synopsis: TLS extra default values and helpers
    Default available version: 0.6.6
    Installed versions: 0.6.5
    Homepage: http://github.com/vincenthz/hs-tls
    License:  BSD3

I ran cabal install to update both tls , http-conduit and still got the same error.

CountOren
  • 844
  • 1
  • 9
  • 27
  • 1
    Are you positive that your Bearer token is correct? – codygman Feb 02 '14 at 22:31
  • Yes it is, the curl request is working fine. – CountOren Feb 03 '14 at 01:51
  • This error is coming from tls, meaning there's a problem in the SSL connection itself. I can tell from the API calls you're making that you're on a version of http-conduit less than 2.0. Can you try running upgrading to newer versions of the tls and http-conduit library and see if that resolves the issue? – Michael Snoyman Feb 03 '14 at 05:54
  • Forgot to mention: it would be useful if you updated the question to include the versions you're currently using. – Michael Snoyman Feb 03 '14 at 05:55
  • Thanks Michael, I will do that , But am i parsing correctly the curl request? – CountOren Feb 03 '14 at 15:41
  • After running the same code with HTTP-Conduit 2.0.0.4 i got the same error this are the last lines after running main in GHCI: Loading package http-conduit-2.0.0.4 ... linking ... done. *** Exception: TlsException (HandshakeFailed (Error_Packet_unexpected "Alert [(AlertLevel_Fatal,DecryptError)]" " expected: change cipher")) – CountOren Feb 04 '14 at 02:51
  • Doing this request with the ruby PayPal-SDK works as well. – CountOren Feb 12 '14 at 04:25

0 Answers0