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

Problem with nested dictionary #488

Closed
imetallica opened this issue Oct 18, 2016 · 1 comment
Closed

Problem with nested dictionary #488

imetallica opened this issue Oct 18, 2016 · 1 comment

Comments

@imetallica
Copy link

imetallica commented Oct 18, 2016

Hi guys, I'm trying to do post requests with a nested dictionary, but it does not seem to work. My code:

from locust import HttpLocust, TaskSet, task
import random

class UserBehavior(TaskSet):
  def on_start(self):
    return 0

  @task(2)
  def index(self):
    to_send = {
      "object": "page",
      "entry": [
        {
          "id": random.randint(1, 10000),
          "time": random.randint(1000000, 100000000),
          "messaging": [
            {
              "message": {
                "seq": random.randint(1, 1000),
                "text": "Hello World"
              },
              "recipient": {
                "id": random.randint(1, 10000)
              },
              "sender": {
                "id": random.randint(1, 10000)
              },
              "timestamp": random.randint(1000000, 1000000000)
            }
          ]
        }
      ]
    }
    self.client.post("/api/incoming/facebook", to_send)

class WebsiteUser(HttpLocust):
  task_set = UserBehavior
  min_wait=5000
  max_wait=9000

On my server, I'm only getting:
%{"entry" => "time", "object" => "page"}

@heyman
Copy link
Member

heyman commented Oct 18, 2016

Hi! Locust uses python Requests library.

If you're trying to post the dictionary as a JSON blob you could use the json keyword argument in the post() method. Like this:

self.client.post("/api/incoming/facebook", json=to_send)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants