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 8728221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:35:06+00:00 2026-06-13T08:35:06+00:00

I have a problem with opening PDF file. (i am using Ladon and Python

  • 0

I have a problem with opening PDF file.

(i am using Ladon and Python under mod_wsgi working with Apache2. so on a ubuntu apache server system- switched to windows system)

I’m trying to run the following Python script:

(where, str_pdf_file_name = '/var/www/Accounting_Engine/pdfDocuments/File_name.pdf')

def preview_pdf(self,str_pdf_file_name):
    try:
                if sys.version_info[:2] > (2,3):
                    import subprocess
                    from subprocess import Popen, PIPE
                    k = subprocess.Popen(['evince', str_pdf_file_name],stdout=PIPE)
                    print k.communicate()
                else:
                    os.spawnlp(os.P_NOWAIT, 'evince', 'evince', str_pdf_file_name)
    except Exception,msg:
        return str(msg)
    return str_pdf_file_name

I have disabled the stdin and stdout restrictions in apache2.conf file as

WSGIRestrictStdin Off    
WSGIRestrictStdout Off

and now the error.log file shows (/var/log/apache2/error.log):

Cannot parse arguments: Cannot open display: [Wed Oct 10 11:50:24 2012] [error] ('', None)

I have checked os.environ also. It shows like:

{'LANG': 'C', 'APACHE_RUN_USER': 'www-data', 'APACHE_PID_FILE': '/var/run/apache2.pid', 'PWD': '/home/user', 'APACHE_RUN_GROUP': 'www-data', 'PATH': '/usr/local/bin:/usr/bin:/bin'}

I have also tried by changing the PWD by using the following codes:

import pwd
os.environ["PWD"] = pwd.getpwuid(os.getuid()).pw_dir    # Because PWD of 'www-data' was '/var/www'
k = subprocess.Popen(['evince', str_pdf_file_name],env=os.environ,stdout=PIPE)

But their is no change in output. It still shows

'Cannot parse arguments: Cannot open display:'

Any suggestions what could be the cause and how to solve this?

  • 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-13T08:35:07+00:00Added an answer on June 13, 2026 at 8:35 am
    #   Fetch the pdf file from the server,  and keep it in the local matchine
        str_loc_file_path = self.fetch_generated_pdf_file_from_server(str_file_path)
    
    #   Display the fetched file in local matchine
        self.print_pdf(str_loc_file_path)
    
    def fetch_generated_pdf_file_from_server(self, str_file_path,*args):
        import httplib
        import urllib
        conn = httplib.HTTPConnection("192.168.2.10")
        str_loc_file_path = '/home/sreejith/pdfDocuments/__filenew__.pdf'
        locfile = open(str_loc_file_path,'w')
        conn.request("POST",str_file_path)
        response = conn.getresponse()
        locfile.write(response.read())
        locfile.close()
        print "Server Response status is"+str(response.status)+", Because of response "+str(response.reason)
        print response.getheaders()    
        return str_loc_file_path
    
    def print_pdf(self,str_file_name,*args):     # PRINT THE PDF FILE, str_file_name.
        try:
            if sys.platform == "win32":      # IS OS == WINDOWS
                import win32api          # PRINT WITH ADOBE VIEWER. SO IT MUST BE INSTALLED
                win32api.ShellExecute(0, "print", str_file_name, None, ".", 0)
            else:                # CAN'T PRINT IF OS IS LINUX, SO OPEN BY A VIEWER FROM WHICH HE CAN PRINT
                if sys.version_info[:2] > (2,3):
                    import subprocess
                    from subprocess import PIPE
                    k = subprocess.Popen(['evince', str_file_name],stdout=PIPE)
                    k.communicate()
    
                else:
                    k = os.spawnlp(os.P_NOWAIT, 'evince', 'evince', str_file_name)
        except Exception,msg:
            print str(msg)
            msgDlg = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK)
            msgDlg.set_markup("<span foreground='blue'>Printer Is Not Connected. And "+str(msg)+".</span>")
            msgDlg.run()
            msgDlg.destroy()      
        pass
    

    This works for me. 🙂 Hopes helpful for somebody.

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

Sidebar

Related Questions

I have a problem with opening CF.NET forms using VSTS 2008. It uses the
well I have that problem, im using a lightbox srcipt and im opening an
I have a lil problem with opening new tab in the browser after server
I have a problem while opening a pdf in a UIWebView. Zoom in and
I have a problem opening new window in my python gui app. I have
have a a problem with opening a new window using javascript. In Chrome and
I have a problem with IE8 and the opening of a new window with
I have a problem here with this code. I'm opening a socket, then listening
I have problem with my query on C, I’m using the oci8 driver. This
I have a name clashing problem while opening some .Net assemblies in my F#

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.