Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http.Request doesn't allow URL with spaces inside of it #6936

Open
wrussell1999 opened this issue Jan 24, 2025 · 6 comments
Open

http.Request doesn't allow URL with spaces inside of it #6936

wrussell1999 opened this issue Jan 24, 2025 · 6 comments
Labels
area/plugin Plugin-related issue or feature request bug Something isn't working

Comments

@wrussell1999
Copy link
Member

Describe the issue

This user wanted to make a HTTP Request using the variable api_url which contains spaces.

id: nyc-ems-calls-ingestion
namespace: nyc-ems-calls-namespace

variables:
  start_date: "{{ now() | dateAdd(-10, 'YEARS') | date('yyyy-MM-dd') }}"
  api_url: "https://data.cityofnewyork.us/resource/76xm-jjuj?$where=incident_datetime between '{{ render(vars.start_date) }}T00:00:00' and '{{ render(vars.start_date)}}T12:00:00'&$limit=50000" 

tasks:
  - id: check_url
    type: io.kestra.plugin.core.log.Log
    message:
      - "{{render(vars.api_url)}}"
  
  - id: python
    type: io.kestra.plugin.scripts.python.Script
    script: |
      import pandas as pd
      import requests
      import json 

      url = "{{render(vars.api_url)}}"
      r = requests.get(url)
      df = pd.DataFrame(json.loads(r.text))
      print(df.shape)
    beforeCommands:
      - pip install requests pandas
  
  - id: api
    type: io.kestra.plugin.core.http.Request
    uri: "{{ render(vars.api_url) }}"

Now this is a valid request when put into a browser and works with the python task however Kestra threw an error because of the space:

Illegal character in query at index 73: https://data.cityofnewyork.us/resource/76xm-jjuj?$where=incident_datetime between '2015-01-24T00:00:00' and '2015-01-24T12:00:00'&$limit=50000

It works if you replace the spaces with %20 instead. Can we have the plugin do something like this automatically if the spaces exist like a browser does?

Environment

  • Kestra Version: latest
@wrussell1999 wrussell1999 added area/backend Needs backend code changes area/frontend Needs frontend code changes bug Something isn't working labels Jan 24, 2025
@github-project-automation github-project-automation bot moved this to Backlog in Issues Jan 24, 2025
@MilosPaunovic MilosPaunovic added area/plugin Plugin-related issue or feature request and removed area/backend Needs backend code changes area/frontend Needs frontend code changes labels Jan 24, 2025
@deepPublicGit
Copy link

Which plugin does this belong to?

@wrussell1999
Copy link
Member Author

Which plugin does this belong to?

The core plugins

@Ben8t
Copy link
Member

Ben8t commented Jan 27, 2025

Now this is a valid request when put into a browser and works with the python task

I think both browser engine and Python request lib encode the url properly on the backend. In Kestra you can use the urlencode Pebble function to manage such case properly

@Ben8t Ben8t closed this as completed Jan 27, 2025
@github-project-automation github-project-automation bot moved this from Backlog to Done in Issues Jan 27, 2025
@anna-geller
Copy link
Member

let's explore during the cooldown if we can do that under the hood

@anna-geller anna-geller reopened this Jan 27, 2025
@github-project-automation github-project-automation bot moved this from Done to Backlog in Issues Jan 27, 2025
@anna-geller anna-geller added the kind/cooldown Great candidate for the cooldown period label Jan 28, 2025
@anna-geller
Copy link
Member

@loicmathieu would be cool if you could have a look during the cooldown. the question here is: could we check within the HTTP plugin if the URL contains spaces and if so, replace each space with %20

@loicmathieu
Copy link
Member

It's a bug, URL must be URL encoded, not a cooldown investiguation.

@loicmathieu loicmathieu removed their assignment Feb 3, 2025
@loicmathieu loicmathieu removed the kind/cooldown Great candidate for the cooldown period label Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/plugin Plugin-related issue or feature request bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

6 participants