Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Jamal CHAQOURI
    @redarqas_twitter

    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
    @anicolaspp
    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
    @andreak

    Hi
    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
        }
    }
    xraybat
    @xraybat

    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")
    pprintln(resp.statusCode)
    pprintln(resp.text())

    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.
    val resp = requests.get(s"$host/echo")
                        ^
    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.)

    xraybat
    @xraybat

    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...

    xraybat
    @xraybat
    (altho sbt 1.3.x apparently uses coursier out of the box anyway…)
    Olivier COUSIN
    @oeil2lynx
    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
           println(r.toString)
    Magnus Larsson
    @Magua
    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.
    kara
    @karahanozturk
    Hi,
    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
    @jeydurai
    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(
    "http://....",
    data=ujson.Obj("username" -> username).render(),
    headers=Map(
    "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
    @einholen

    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)
    val res1 = requests.post("http://localhost:9000", data = ujson.Obj("hello" -> "world"))
                        ^
    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
    zetashift
    @zetashift
    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
    @rarodriguez94
    You could include a readTimeout if the server takes time to get back
    zetashift
    @zetashift
    @rarodriguez94 thanks!
    Marco Graziano
    @marcoeg

    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
          requests.post(

    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?
    Cheers.

    Yair Ogen
    @yairogen
    Hi, can anyone take a look at this issue and maybe give some pointers?
    com-lihaoyi/requests-scala#88
    Benjamin Kha
    @benkha
    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
    @benkha
    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
    Ayoub
    @I_am_ayoub_twitter

    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