Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

402
Views
Error when using test_client (Flask) - raise ValueError("unknown url type: %r" % self.full_url)

flask application code:

# main.py 
from flask import Flask, Response
app = Flask(__name__)


@app.route("/", methods=["POST"])
def post_example():
    return Response("aaa")

and this is my testing code:

# e2e.py
from main import app

test_client = app.test_client()


def test_flask_api_call():
    response = test_client.post("/", {"a": "b"})
    pass

I keep receiving:

raise ValueError("unknown url type: %r" % self.full_url)
ValueError: unknown url type: '://%7B%27a%27:%20%27b%27%7D/'
   
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The problem is on the post method call. You have to name your data arguments client.post("/", data={"a": "b"}), if it's not the case it is considered as a part of the URL.

urllib.parse.quote("/" + str({"a": "b"}))
# '/%7B%27a%27%3A%20%27b%27%7D'

Here is the test code rewritten to define a fixture for the client initialization. More info on testing flask application on the official doc.

import pytest

from main import app


@pytest.fixture(scope="module")
def client():
    with app.test_client() as client:
        yield client


def test_flask_api_call(client):
    response = client.post("/", data={"a": "b"})
    assert response.status_code == 200, f"Got bad status code {response.status_code}"
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!