Python Recipe debugging-

Solved!
Oh_Lily
Level 2
Python Recipe debugging-

Hello, 
I am trying to export a folder with my result tables using a python recipe.
I am also trying to name each table differently.
Here is my code: 
I keep getting this error when I run my code: 

 At line 43: <class 'TypeError'>: a bytes-like object is required, not 'str'

Any idea how to debug please?
Thanks in advance 

 

 

 

def export_data(table,scope,liste_region):
    for region in liste_region :
        with export_DATA.get_writer(region + "/REPORT_AXIS_" +scope+ "_RG_"+ region + "_" + brand_filter + "_" + date_deb + "_" + date_fin + "_" + now + ".csv") as export_data:
                export_data.write(table[table['Region']== str(region)].to_csv(index=False))

 

 

 

 

0 Kudos
1 Solution
FlorentD
Developer Advocate

Hi @Oh_Lily,

the trouble comes from

with export_DATA.get_writer(region + "/REPORT_AXIS_" +scope+ "_RG_"+ region + "_" + brand_filter + "_" + date_deb + "_" + date_fin + "_" + now + ".csv") as export_data:
                export_data.write(table[table['Region']== str(region)].to_csv(index=False))

You can't write directly a string, maybe putting an `encode()` will help to write, something like:

with export_DATA.get_writer(region + "/REPORT_AXIS_" +scope+ "_RG_"+ region + "_" + brand_filter + "_" + date_deb + "_" + date_fin + "_" + now + ".csv") as export_data:
                export_data.write(table[table['Region']== str(region)].to_csv(index=False).encode())

 

Hope this helps,

Best

View solution in original post

2 Replies
FlorentD
Developer Advocate

Hi @Oh_Lily,

the trouble comes from

with export_DATA.get_writer(region + "/REPORT_AXIS_" +scope+ "_RG_"+ region + "_" + brand_filter + "_" + date_deb + "_" + date_fin + "_" + now + ".csv") as export_data:
                export_data.write(table[table['Region']== str(region)].to_csv(index=False))

You can't write directly a string, maybe putting an `encode()` will help to write, something like:

with export_DATA.get_writer(region + "/REPORT_AXIS_" +scope+ "_RG_"+ region + "_" + brand_filter + "_" + date_deb + "_" + date_fin + "_" + now + ".csv") as export_data:
                export_data.write(table[table['Region']== str(region)].to_csv(index=False).encode())

 

Hope this helps,

Best

Oh_Lily
Level 2
Author

Hello, 
YES it works!! 
thanks a lot for your help !! 

0 Kudos