0

I've sent request use POST method

response = user.post(url , data)

here is the YAML data:


description: "{{text}}"
tags: 
  - "{{tags}}"
private: true
background: "{{background}}"
name: "{{name}}"

i'm using Faker for the lazy data and here is the format:

    def tags(self):
        format = [
            'blue',
            'gray',
            'took a while',
            'tag, new',
            'work',
            'whatever',
            'tag',
            'truck',
            'merchant card'
            ]
        return self.random_element(format)

And this is the data after I rendered

{'tags': '-"work"', 'private': True, 'background': 'black', 'name': 'Mr. Shayne Sauer', 'description': 'Architecto quod laudantium corporis ex voluptatibus dolorem sint nisi. Id maiores reiciendis sequi. Non non qui nulla rerum non veniam.'}

here is the response after sent request

'{"_status": "ERR", "_issues": {"tags": "must be of list type"}, "_error": {"message": "Insertion failure: 1 document(s) contain(s) error(s)", "code": 422}}'

My question is how to render YAML data to a list??

khue bui
  • 1,366
  • 3
  • 22
  • 30

1 Answers1

2

You need to have a space between your - and the subsequent value. You want this:

tags: 
  - "{{tags}}"

...or just:

tags: [ "{{tags}}" ]
Jordan Running
  • 102,619
  • 17
  • 182
  • 182
  • It's really hard to read code in comments. Please edit your question. As I said above, you need a space between the `-` and first `"`. – Jordan Running Jan 19 '16 at 01:44
  • without space between the - and the subsequent value, it rise the Error Syntax ` yaml.scanner.ScannerError: while scanning a simple key in "", line 4, column 3: -"{{tags}}" ^ could not found expected ':' ` the second way, it's not parse – khue bui Jan 19 '16 at 01:58
  • Yes, that's what I wrote. And as I wrote, the solution is to put a space there. – Jordan Running Jan 19 '16 at 01:58
  • tks for your help, but it still not parse the value that i want to render, "put a space there" will not parse – khue bui Jan 19 '16 at 02:02
  • Please edit your question to include the changes you've made. – Jordan Running Jan 19 '16 at 02:03
  • I put a space there, it still not parse @Jordan – khue bui Jan 19 '16 at 02:05
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/101031/discussion-between-khue-bui-and-jordan). – khue bui Jan 19 '16 at 02:06
  • Okay, well, without seeing the code you have now and the YAML it renders or the data structure parsed from it I really can't help you. – Jordan Running Jan 19 '16 at 02:06
  • hi, i've edited the code in the question above, i just change in tags as you said, but it not work – khue bui Jan 19 '16 at 02:17