راکت
حل شده

ساخت فایل DBF با پایتون

1 پاسخ

پکیج مناسب برای ساخت فایل DBF برای ارسال دیسکت بیمه تامین اجتماعی
فایلی که با ماژول DBF پایتون ساخته میشود را قبول نمی کند
لطفا راهنمایی کنید

ثبت پرسش جدید

پاسخ‌ها

1
سروش مرشدی
سروش مرشدی
@sorooshMorshedi

تخصص: Senior Software Architect & Full-Stack Engineer

بهترین پاسخ

If you're generating a DBF file for submission to Iran's Social Security Organization (Tamin Ejtemaei), the problem is often not simply whether Python can create a DBF file. These systems are based on a fairly old DBF specification and can be very strict about the file structure, field definitions, encoding, and code page.

One important point from experience: don't assume UTF-8 is the correct encoding just because the data contains Persian. With older DBF-based systems, UTF-8 can actually break compatibility.

For Persian/Arabic data, you may need to use an Arabic-compatible code page such as Windows-1256, depending on what the receiving system expects.

For example:

from dbfread import DBF

table = DBF(
    "insurance.dbf",
    encoding="cp1256"
)

However, if you're creating the DBF rather than reading it, simply setting encoding="cp1256" may not be enough. You need to make sure the DBF writer creates the correct field types, field lengths, code-page information, and byte encoding expected by the Tamin Ejtemaei software.

Also, because these submission systems are quite old, UTF-8 can cause problems. In some cases, the practical solution is to use a custom encoding layer/code page that maps the required Persian and Arabic characters correctly before writing the DBF.

So I'd approach it this way:

  1. Check the exact DBF structure required by Tamin Ejtemaei.
  2. Match the field names, types, and lengths exactly.
  3. Use the expected legacy code page rather than blindly using UTF-8.
  4. If the standard Python DBF package doesn't generate a compatible file, implement/customize the encoding layer so both Persian and Arabic characters are represented correctly.
  5. Compare the generated DBF at the byte level with a known-good file accepted by the system.

The last step is especially useful with legacy systems: if you have one DBF file that Tamin Ejtemaei accepts, comparing its header, field descriptors, code-page information, and encoded Persian bytes against your generated file will usually reveal what's actually wrong.

Soroosh Morshedi
sorooshmorshedi.com

شاید پاسخ شما همین‌جا باشد

برای ارسال پاسخ لازم است وارد شده یا ثبت‌نام کنید

ورود یا ثبت‌نام