question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ValueError: Elements in iterable body must be bytestrings

See original GitHub issue

Hello! Thank you for such a great tool!

I’m experiencing with an error trying to send request to API server. It seems the request is OK, but there is a problem with response - HTTPie can’t parse it. Here is an example:

~$ http --print hbHB POST 'https://cloud.roistat.com/api/v1/project/analytics/data?project=48526&key=XXX' dimensions:='["marker_level_1"]' period:='{"from": "2020-10-01","to": "2020-11-01"}' metrics:='["visits"]'
POST /api/v1/project/analytics/data?project=48526&key=XXX HTTP/1.1
Accept: application/json, */*;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 111
Content-Type: application/json
Host: cloud.roistat.com
User-Agent: HTTPie/2.3.0

{
    "dimensions": [
        "marker_level_1"
    ],
    "metrics": [
        "visits"
    ],
    "period": {
        "from": "2020-10-01",
        "to": "2020-11-01"
    }
}

http: error: ValueError: Elements in iterable body must be bytestrings. Illegal element: {

I’ve emulated request to API server using CURL, and the response is:

$ curl -i -X POST -H "Content-Type: application/json" -d @json.json 'https://cloud.roistat.com/api/v1/project/analytics/data?project=48526&key=XXX'
HTTP/1.1 200 OK
Server: nginx/1.8.0
Date: Fri, 20 Nov 2020 07:12:08 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Cache-Control: no-cache, must-revalidate
Vary: Accept-Encoding
X-Powered-By: PHP/7.1.33-16+0~20200514.38+debian9~1.gbp1e5820

{"data":[{"items":[{"metrics":[{"value":627,"formatted":null,"metric_name":"visits","attribution_model_id":"default"},{"value":627,"formatted":null,"metric_name":"visitCount","attribution_model_id":"default"}],"dimensions":{"marker_level_1":{"value":":utm:vk","title":"vk","icon":"https:\/\/favicon.yandex.net\/favicon\/vk.com"}},"isHasChild":0},{"metrics":[{"value":0,"formatted":null,"metric_name":"visits","attribution_model_id":"default"},{"value":0,"formatted":null,"metric_name":"visitCount","attribution_model_id":"default"}],"dimensions":{"marker_level_1":{"value":"визитка","title":"визитка","icon":""}},"isHasChild":0},{"metrics":[{"value":10118,"formatted":null,"metric_name":"visits","attribution_model_id":"default"},{"value":10118,"formatted":null,"metric_name":"visitCount","attribution_model_id":"default"}],"dimensions":{"marker_level_1":{"value":"","title":"Прямые визиты","icon":"https:\/\/cloud.roistat.com\/img\/arrow-right.png"}},"isHasChild":0},{"metrics":[{"value":10,"formatted":null,"metric_name":"visits","attribution_model_id":"default"},{"value":10,"formatted":null,"metric_name":"visitCount","attribution_model_id":"default"}],"dimensions":{"marker_level_1":{"value":":utm:mom.life","title":"mom.life","icon":""}},"isHasChild":0},{"metrics":[{"value":0,"formatted":null,"metric_name":"visits","attribution_model_id":"default"},{"value":0,"formatted":null,"metric_name":"visitCount","attribution_model_id":"default"}],"dimensions":{"marker_level_1":{"value":"bot","title":"Роботы","icon":"https:\/\/cloud.roistat.com\/img\/r2d2.png"}},"isHasChild":0},{"metrics":[{"value":24,"formatted":null,"metric_name":"visits","attribution_model_id":"default"},{"value":24,"formatted":null,"metric_name":"visitCount","attribution_model_id":"default"}],"dimensions":{"marker_level_1":{"value":":utm:regmarkets","title":"regmarkets","icon":""}},"isHasChild":0},{"metrics":[{"value":2,"formatted":null,"metric_name":"visits","attribution_model_id":"default"},{"value":2,"formatted":null,"metric_name":"visitCount","attribution_model_id":"default"}],"dimensions":{"marker_level_1":{"value":":utm:glami","title":"glami","icon":""}},"isHasChild":0},{"metrics":[{"value":1,"formatted":null,"metric_name":"visits","attribution_model_id":"default"},{"value":1,"formatted":null,"metric_name":"visitCount","attribution_model_id":"default"}],"dimensions":{"marker_level_1":{"value":":utm:yp.ru","title":"yp.ru","icon":""}},"isHasChild":0},{"metrics":[{"value":50,"formatted":null,"metric_name":"visits","attribution_model_id":"default"},{"value":50,"formatted":null,"metric_name":"visitCount","attribution_model_id":"default"}],"dimensions":{"marker_level_1":{"value":":utm:email","title":"email","icon":"https:\/\/cloud.roistat.com\/img\/email.png"}},"isHasChild":0},{"metrics":[{"value":1022,"formatted":null,"metric_name":"visits","attribution_model_id":"default"},{"value":1022,"formatted":null,"metric_name":"visitCount","attribution_model_id":"default"}],"dimensions":{"marker_level_1":{"value":"yamarket8","title":"Яндекс.Маркет","icon":"https:\/\/favicon.yandex.net\/favicon\/market.yandex.ru"}},"isHasChild":0},{"metrics":[{"value":4460,"formatted":null,"metric_name":"visits","attribution_model_id":"default"},{"value":4460,"formatted":null,"metric_name":"visitCount","attribution_model_id":"default"}],"dimensions":{"marker_level_1":{"value":":utm:convead","title":"convead","icon":""}},"isHasChild":0},{"metrics":[{"value":24,"formatted":null,"metric_name":"visits","attribution_model_id":"default"},{"value":24,"formatted":null,"metric_name":"visitCount","attribution_model_id":"default"}],"dimensions":{"marker_level_1":{"value":":utm:fb","title":"fb","icon":"https:\/\/favicon.yandex.net\/favicon\/facebook.com"}},"isHasChild":0},{"metrics":[{"value":9226,"formatted":null,"metric_name":"visits","attribution_model_id":"default"},{"value":9226,"formatted":null,"metric_name":"visitCount","attribution_model_id":"default"}],"dimensions":{"marker_level_1":{"value":":utm:admitad","title":"admitad","icon":""}},"isHasChild":0},{"metrics":[{"value":1,"formatted":null,"metric_name":"visits","attribution_model_id":"default"},{"value":1,"formatted":null,"metric_name":"visitCount","attribution_model_id":"default"}],"dimensions":{"marker_level_1":{"value":":utm:criteo","title":"criteo","icon":""}},"isHasChild":0},{"metrics":[{"value":42,"formatted":null,"metric_name":"visits","attribution_model_id":"default"},{"value":42,"formatted":null,"metric_name":"visitCount","attribution_model_id":"default"}],"dimensions":{"marker_level_1":{"value":":utm:source:u:youtube","title":"source_youtube","icon":"https:\/\/favicon.yandex.net\/favicon\/youtube.com"}},"isHasChild":0},{"metrics":[{"value":18,"formatted":null,"metric_name":"visits","attribution_model_id":"default"},{"value":18,"formatted":null,"metric_name":"visitCount","attribution_model_id":"default"}],"dimensions":{"marker_level_1":{"value":":utm:alpfederation","title":"alpfederation","icon":""}},"isHasChild":0},{"metrics":[{"value":238,"formatted":null,"metric_name":"visits","attribution_model_id":"default"},{"value":238,"formatted":null,"metric_name":"visitCount","attribution_model_id":"default"}],"dimensions":{"marker_level_1":{"value":"unmarked","title":"Неразмеченные объявления","icon":""}},"isHasChild":0},{"metrics":[{"value":1,"formatted":null,"metric_name":"visits","attribution_model_id":"default"},{"value":1,"formatted":null,"metric_name":"visitCount","attribution_model_id":"default"}],"dimensions":{"marker_level_1":{"value":":openstat:bwfya2v0lnlhbmrlec5ydtvqotgd0ydqungb0ylqungh0lxrgdc60ldrjydqv9c-0yhrg9c00lags292zwegrxnjyxblozbqn1zkz25hynjqqzbrwwfhag9dmgc7","title":"bwfya2v0lnlhbmrlec5ydtvqotgd0ydqungb0ylqungh0lxrgdc60ldrjydqv9c-0yhrg9c00lags292zwegrxnjyxblozbqn1zkz25hynjqqzbrwwfhag9dmgc7","icon":""}},"isHasChild":0},{"metrics":[{"value":0,"formatted":null,"metric_name":"visits","attribution_model_id":"default"},{"value":0,"formatted":null,"metric_name":"visitCount","attribution_model_id":"default"}],"dimensions":{"marker_level_1":{"value":"unknown","title":"Нет значения","icon":""}},"isHasChild":0},{"metrics":[{"value":1,"formatted":null,"metric_name":"visits","attribution_model_id":"default"},{"value":1,"formatted":null,"metric_name":"visitCount","attribution_model_id":"default"}],"dimensions":{"marker_level_1":{"value":":utm:propartner:u:ru","title":"propartner_ru","icon":""}},"isHasChild":0},{"metrics":[{"value":23,"formatted":null,"metric_name":"visits","attribution_model_id":"default"},{"value":23,"formatted":null,"metric_name":"visitCount","attribution_model_id":"default"}],"dimensions":{"marker_level_1":{"value":":utm:baskru","title":"baskru","icon":""}},"isHasChild":0},{"metrics":[{"value":3,"formatted":null,"metric_name":"visits","attribution_model_id":"default"},{"value":3,"formatted":null,"metric_name":"visitCount","attribution_model_id":"default"}],"dimensions":{"marker_level_1":{"value":":utm:yell.ru","title":"yell.ru","icon":""}},"isHasChild":0},{"metrics":[{"value":44471,"formatted":null,"metric_name":"visits","attribution_model_id":"default"},{"value":44471,"formatted":null,"metric_name":"visitCount","attribution_model_id":"default"}],"dimensions":{"marker_level_1":{"value":"seo","title":"SEO","icon":"https:\/\/cloud.roistat.com\/img\/MagnifyingGlass.png"}},"isHasChild":0},{"metrics":[{"value":1309,"formatted":null,"metric_name":"visits","attribution_model_id":"default"},{"value":1309,"formatted":null,"metric_name":"visitCount","attribution_model_id":"default"}],"dimensions":{"marker_level_1":{"value":"marketplace","title":"marketplace","icon":""}},"isHasChild":0},{"metrics":[{"value":1,"formatted":null,"metric_name":"visits","attribution_model_id":"default"},{"value":1,"formatted":null,"metric_name":"visitCount","attribution_model_id":"default"}],"dimensions":{"marker_level_1":{"value":"google10","title":"google","icon":"https:\/\/cloud.roistat.com\/img\/engines\/ga.png"}},"isHasChild":0},{"metrics":[{"value":1,"formatted":null,"metric_name":"visits","attribution_model_id":"default"},{"value":1,"formatted":null,"metric_name":"visitCount","attribution_model_id":"default"}],"dimensions":{"marker_level_1":{"value":":utm:nativerent","title":"nativerent","icon":""}},"isHasChild":0},{"metrics":[{"value":2,"formatted":null,"metric_name":"visits","attribution_model_id":"default"},{"value":2,"formatted":null,"metric_name":"visitCount","attribution_model_id":"default"}],"dimensions":{"marker_level_1":{"value":":openstat:market.yandex.ru","title":"market.yandex.ru","icon":""}},"isHasChild":0},{"metrics":[{"value":13692,"formatted":null,"metric_name":"visits","attribution_model_id":"default"},{"value":13692,"formatted":null,"metric_name":"visitCount","attribution_model_id":"default"}],"dimensions":{"marker_level_1":{"value":"site","title":"Визиты с сайтов","icon":"https:\/\/cloud.roistat.com\/img\/globe.png"}},"isHasChild":0}],"mean":{"metrics":[{"value":85367,"formatted":null,"metric_name":"visits","attribution_model_id":"default"},{"value":85367,"formatted":null,"metric_name":"visitCount","attribution_model_id":"default"}],"dimensions":[],"isHasChild":0},"dateFrom":"2020-10-01T00:00:00+0000","dateTo":"2020-11-01T00:00:00+0000","unprocessed":{"visits":0,"leads":0}}],"status":"success"}

So it seems the problem in HTTPie. Is it possible to handle with it?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:18 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
BoboTiGcommented, Sep 23, 2021

The issue with HTTP/2 is more tricky than expected. We will fix everything at some point (see https://github.com/httpie/httpie/issues/692#issuecomment-646354697).

1reaction
BoboTiGcommented, Sep 23, 2021

(And you remove your comment, I copied the key.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Type error: POST data should be bytes; also user-agent issue
I am aware of this similar question, TypeError: POST data should be bytes or an iterable of bytes. It cannot be str, but...
Read more >
Interface — hyper 0.7.0 documentation
The Content-Length header is set to the length of the body field. ... Must be a bytestring or a file-like object. headers –...
Read more >
hyper.compat.bytes Example - Program Talk
... sum(len(bytes(x)) for x in body) with pytest.raises(ValueError) as ... str(body_size)} ) assert 'Elements in iterable body must be bytestrings.
Read more >
Built-in Types — Python 3.11.1 documentation
Return the integer represented by the given array of bytes. The argument bytes must either be a bytes-like object or an iterable producing...
Read more >
Requests Documentation - Read the Docs
Note: All header values must be a string, bytestring, or unicode. ... provide a generator (or any iterator without a length) for your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found