Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9124159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:30:39+00:00 2026-06-17T06:30:39+00:00

I’m using embedded python in my C program. The python script grabs a file

  • 0

I’m using embedded python in my C program. The python script grabs a file from an online source and returns the data it received.

The C part of my program that envolves this particular script is the following:

char* Drop::getFile(std::string path){
  PyObject *pValue;
  char* fileData = NULL;
  pFunc = PyObject_GetAttrString(pModule,"getFile");
  pArgs = PyTuple_New(1);
  PyTuple_SetItem(pArgs,0,PyString_FromString(path.c_str()));
  pValue = PyObject_CallObject(pFunc,pArgs);
  fileData = PyString_AsString(pValue); 
  Py_DECREF(pFunc);
  Py_DECREF(pArgs);
  return fileData;
}

fileData does get a value, but the data it points to doesn’t match what the python script pulled from the net. What I’m testing this on is a pdf file

%PDF-1.4%âãÏÓ
194 0 obj<>endobj
xref
194 28
0000000016 00000 n
0000001374 00000 n
0000001521 00000 n
0000001915 00000 n
0000002047 00000 n
0000002547 00000 n
0000002661 00000 n
0000002773 00000 n
0000002800 00000 n
0000003401 00000 n
0000003656 00000 n
0000004166 00000 n
0000005703 00000 n
0000006124 00000 n
0000006373 00000 n
0000006828 00000 n
0000006898 00000 n
0000007022 00000 n
0000031268 00000 n
0000031531 00000 n
0000032131 00000 n
0000056344 00000 n
0000079808 00000 n
0000080674 00000 n
0000085029 00000 n
0000085946 00000 n
0000001196 00000 n
0000000873 00000 n
trailer
<> <6F4E88EE2CFAE8419CCB5AF471C4A73F>]/Prev 241987/XRefStm 1196>>
startxref
0
%%EOF

221 0 obj<>stream
hÞb`bYÇÀÆÀÀÆ È

But the actual file is much longer. I’m at a lost on why the data is being cut.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:30:40+00:00Added an answer on June 17, 2026 at 6:30 am

    You need to use PyString_AsStringAndSize and use the length of the file as well as the bytes returned. If you treat the returned bytes as a c-string, you’ll interpret the first 0-byte as the end of the string.

    In general, you must be careful when using string functions on binary data in C for exactly this reason.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am using jsonparser to parse data and images obtained from json response. When
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am using JSon response to parse title,date content and thumbnail images and place
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.