# When I try to index a jason file using "es.helpers.bulk" the error "TypeError: pop expected at most 1 argument, got 2" is occurring

**URL:** <https://discuss.elastic.co/t/when-i-try-to-index-a-jason-file-using-es-helpers-bulk-the-error-typeerror-pop-expected-at-most-1-argument-got-2-is-occurring/322828>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [January 10, 2023, 12:06pm UTC](https://discuss.elastic.co/t/when-i-try-to-index-a-jason-file-using-es-helpers-bulk-the-error-typeerror-pop-expected-at-most-1-argument-got-2-is-occurring/322828 "2023-01-10T12:06:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pand](https://avatars.discourse-cdn.com/v4/letter/p/b38774/32.png) [@pand](https://discuss.elastic.co/u/pand)\
**Post date:** [January 10, 2023, 12:06pm UTC](https://discuss.elastic.co/t/when-i-try-to-index-a-jason-file-using-es-helpers-bulk-the-error-typeerror-pop-expected-at-most-1-argument-got-2-is-occurring/322828/1 "2023-01-10T12:06:01Z")

</div>

When I execute the following code the error "TypeError: pop expected at most 1 argument, got 2" is occuring, please provide solutions to fix this.

```auto
def creatdocs(filename,pdfcontent):
    docs = [{
            'content': paragraph,
            'meta': {
            'source': filename
            }   
        }for paragraph in pdfcontent
    ]
    yield docs

```

```auto
#calling the function:
helpers.bulk(es, creatdocs(filename,pdfcontent),index='indexname2')

```

## Error:

```auto
Traceback (most recent call last):
  
 File "C:\Python 3.10.7\lib\site-packages\elasticsearch\helpers\actions.py", line 524, in bulk
    for ok, item in streaming_bulk(
  File "C:\Python 3.10.7\lib\site-packages\elasticsearch\helpers\actions.py", line 422, in streaming_bulk
    for bulk_data, bulk_actions in _chunk_actions(
  File "C:\Python 3.10.7\lib\site-packages\elasticsearch\helpers\actions.py", line 232, in _chunk_actions
    for action, data in actions:
  File "C:\Python 3.10.7\lib\site-packages\elasticsearch\helpers\actions.py", line 65, in expand_action
    op_type: str = data.pop("_op_type", "index")
TypeError: pop expected at most 1 argument, got 2

```

Version:  
Python 3.10.7  
Elasticsearch client 8.5.3  
Elasticsearch server 8.5.3

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 10, 2023, 4:16pm UTC](https://discuss.elastic.co/t/when-i-try-to-index-a-jason-file-using-es-helpers-bulk-the-error-typeerror-pop-expected-at-most-1-argument-got-2-is-occurring/322828/2 "2023-01-10T16:16:34Z")

</div>

Welcome!

I'm not sure but it looks like the header of each line is missing...

---

<div class="post-metadata">

**Author:** ![pand](https://avatars.discourse-cdn.com/v4/letter/p/b38774/32.png) [@pand](https://discuss.elastic.co/u/pand)\
**Post date:** [January 11, 2023, 4:54pm UTC](https://discuss.elastic.co/t/when-i-try-to-index-a-jason-file-using-es-helpers-bulk-the-error-typeerror-pop-expected-at-most-1-argument-got-2-is-occurring/322828/3 "2023-01-11T16:54:09Z")

</div>

But the following code works well, if we call the "helpers.bulk()" next to the json,

```auto
def creatdocs(filename,pdfcontent):
    docs = [{
            'content': paragraph,
            'meta': {
            'source': filename
            }   
        }for paragraph in pdfcontent
    ]
helpers.bulk(es,docs,index='statutory2')

```

The error occurs only if we call the "helpers.bulk()" from outside of the function.

I did some analysis on the piece of code in the "action.py"  
Python 3.10.7\lib\site-packages\elasticsearch\helpers\actions.py", line 65,

```auto

op_type: str = data.pop("_op_type", "index")

```

Created the following two lines of code and executed which produces the same error.

```auto
data=[{"Lion","Tiger","Giraffe",'Panda'}]
op_type: str = data.pop("_op_type", "index")

```

I tried many possibilities but no luck, please provide your idea or solution which will help me to fix this.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 8, 2023, 4:54pm UTC](https://discuss.elastic.co/t/when-i-try-to-index-a-jason-file-using-es-helpers-bulk-the-error-typeerror-pop-expected-at-most-1-argument-got-2-is-occurring/322828/4 "2023-02-08T16:54:18Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
