Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    import $ivy.`com.lihaoyi::requests:0.1.5`
    val r = requests.post("http://httpbin.org/post", data = Map("key" -> "value"))
    Do you know what's misssing ?
    $ ./HttpClient-requests.scala
    Exception in thread "main" java.lang.ClassNotFoundException: $file.`HttpClient-requests`$$routes$
            at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
            at ammonite.interp.SpecialClassLoader.findClass(ClassLoaders.scala:113)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    I updated from ammonite 0.7 to ammonite 1.2, it solved the problem
    Faiaz Sanaulla
    Hello, @lihaoyi thank you for a great project.
    Can you tell me why response headers lowercased by default?
    Why not leave it as it is?
    Nick Childers
    Does requests-scala support downloading chunked gzip files?
    Romain DEP.
    hi there, thumbs up for the great lib.
    Are there any plans to support other kind of proxys? Seems like socks5 isn't supported currently
    Jamal CHAQOURI

    Hi, I think it's not directly related to requests-scala, i did find a simple to do it, let met explain :

    • I create a session for qualifEnv (let us say baseUrl: https://qualif.gatway): `val qualifEnv = requests.Session(some specific config for qualif)
    • Now i do a call: qualifEnvSession.get(s"$baseUrl/resource", ...)

    It could be cool to have a scoped requests instance allowing: qualifEnvSession.get("resource", ...), which takes care about addding the baseUrl.

    I did not find a simple way to do that, if have you ideas, thank you

    with geny.Readable and geny.Writable, and a scoped by env requests instance, we could have a less error prone and smooth tool for data migration between envs
    Nicolas A Perez
    do we have support for proxies on this library?
    @lihaoyi I have been using the lib for a while now, but i need to go through a proxy. Does the library support proxy as the python one?
    Andreas Joseph Krogh

    I'm feeling that the way this library is going forces me to use var more than it should.
    If reading a stream from GET I have to use a var to store the StreamHeaders value and then only read from the stream if response is SC_OK, like this:

    var responseHeaders: Option[StreamHeaders] = None
    requests.get.stream("https://some.url", check = false
        , onHeadersReceived = streamHeaders => {
            responseHeaders = Some(streamHeaders)
            if (streamHeaders.statusCode == HttpServletResponse.SC_OK) {
                // stuff
            } else {
                // other stuff
        }).readBytesThrough{ inputStream =>
        if (responseHeaders.exists(_.statusCode == HttpServletResponse.SC_OK)) {
            // read stream
        } else {
            // don't

    It would be great if one could do this (access streamHeaders in the Readable:

    val readable = requests.get.stream("https://some.url", check = false
        , onHeadersReceived = streamHeaders => {
            if (streamHeaders.statusCode == HttpServletResponse.SC_OK) {
                // stuff
            } else {
                // other stuff
    if (readable.streamHeaders.statusCode == HttpServletResponse.SC_OK) {
        readable.readBytesThrough{ inputStream =>
            // read stream

    i've been working with requests-scala in an (sbt 1.3.7/scala 2.13.1) app with utests without any problems, as per:

    "com.lihaoyi" %% "requests" % "0.5.0",

    however, when i run an ammonite script mimicking the successful utest with ammonite 1.6.3 (scala 2.12.8 on macOS 10.15.3):

    import $ivy.`com.lihaoyi::requests:0.5.0`
    import $ivy.`com.lihaoyi::pprint:0.5.6`, pprint._
    // requires fsm-interface.FsmInterface to be up and running
    val host = "http://localhost:8080"
    val resp = requests.get(s"$host/echo")

    i get

    Compiling /Users/psc/Documents/Development/Scala/fsm/interface/src/main/sc/fsm-interface.sc
    fsm-interface.sc:6: Symbol 'type geny.ByteData' is missing from the classpath.
    This symbol is required by 'class requests.Response'.
    Make sure that type ByteData is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
    A full rebuild may help if 'Response.class' was compiled against an incompatible version of geny.
    fsm-interface.sc:8: value text is not a member of requests.Response
    val res_5 = pprintln(resp.text())
    Compilation Failed

    (the pprint import works fine and can be used.)


    problem above goes away using latest ammonite installed via coursier / cs CLI.

    might be time to move in a coursier / mill direction and away from sbt...

    (altho sbt 1.3.x apparently uses coursier out of the box anyway…)
    Olivier COUSIN
    I've been working with requests-scala but when I have a 404 error, I have a exception with Geny, is that normal ?
    scala>val r = requests.get("https://www.freebsd.org/fsdkfjsdkfd")
    scala> println(r.toString)
    <console>:12: error: not found: value r
    Magnus Larsson
    val r = requests.get("https://www.freebsd.org/fsdkfjsdkfd", check = false)
    New version of requests will throw exceptions for non 2** http return codes. check = false will give the old behavior.
    I had problems with delete method. I was able to get success response from Postman and my react project.
    I later noticed that the body is not sent. I created a PR lihaoyi/requests-scala#65
    This is similar to the PATCH change which was added in January (lihaoyi/requests-scala#47)
    D. Jeyaraj
    I have a Django API based on JWT, from which I have to receive json data. I have been able to get the access token. But, with the following, I am getting the error from the Python server that No Post Data.
    val data: Response = requests.post(
    data=ujson.Obj("username" -> username).render(),
    "Authorization" -> s"Bearer $accessToken",
    "Content-Type" -> "application/json",
    The details "data=ujson.Obj("username" -> username).render()" is supposed to be read in Django API as "request.POST.get('username')"
    Any idea as to how to resolve this?
    Sergey Nastich

    Hello! Any idea if I'm missing an import?
    I'm getting this error by just running a command from requests-scala's readme in amm REPL without any additional imports.

    @ requests.post("http://localhost:9000", data = ujson.Obj("hello" -> "world"))
    cmd1.sc:1: overloaded method value apply with alternatives:
      (r: requests.Request,data: requests.RequestBlob)requests.Response <and>
      (url: String,auth: requests.RequestAuth,params: Iterable[(String, String)],headers: Iterable[(String, String)],data: requests.RequestBlob,readTimeout: Int,connectTimeout: Int,proxy: (String, Int),cookies: Map[String,java.net.HttpCookie],cookieValues: Map[String,String],maxRedirects: Int,verifySslCerts: Boolean,autoDecompress: Boolean,compress: requests.Compress,keepAlive: Boolean)requests.Response
     cannot be applied to (String, data: ujson.Obj)
    Compilation Failed

    I tried importing the library explicitly, with similar results
    import $ivy.{`com.lihaoyi::requests:0.6.5`, `com.lihaoyi::ujson:0.9.5`}

    1 reply
    Anybody know why I'm getting a TimeoutException when running val r = requests.get("https://bad-api-assignment.reaktor.com/v2/availability/okkau/") in Ammonite? In the browser it works fine, I'm not sure why I get a timeout.
    Raul Rodriguez
    You could include a readTimeout if the server takes time to get back
    @rarodriguez94 thanks!
    Marco Graziano

    I am trying to import and use requests in a Databricks notebook.

    I am getting this error:

    command-1361810570373404:40: error: object post is not a member of package requests

    Also, if I try to import the package with import com.lihaoyi.requests._ I am not finding it:

    command-497441197922137:2: error: object lihaoyi is not a member of package com
    import com.lihaoyi.requests._

    Have downloaded the jar from Maven: https://mvnrepository.com/artifact/com.lihaoyi/requests_2.13/0.5.2
    Datbricks runtime 7.5 (includes Apache Spark 3.0.1, Scala 2.12)
    Any idea how to properly import and use the library in Databricks?

    Yair Ogen
    Hi, can anyone take a look at this issue and maybe give some pointers?
    Benjamin Kha
    does requests support a list of query params
    similar to Python
    >>> payload = {'key1': 'value1', 'key2': ['value2', 'value3']}
    >>> r = requests.get('https://httpbin.org/get', params=payload)
    Benjamin Kha
    ah ya thanks, I was talking about the case where you have multiple values for the same value, so passing Map[String, String] wont work
    but looks like you can pass in List[(String, String)], just not in the documentation

    Hi what is the equivalent in request of this curl post request ?

    curl --location --request POST 'https://some.url/foo' \
    --form 'title="MY_TITLE"' \
    --form 'file=@"/PATH/FILE.mp3"'

    If as you can see it is a form post request with both a key value and a file