小编ale*_*kot的帖子

python StringIO 不能作为带有 subrprocess.call() 的文件

我正在使用subprocess包从 python 脚本调用一些外部控制台命令,我需要将文件处理程序传递给它以分别返回stdoutstderr。代码大致如下:

import subprocess

stdout_file = file(os.path.join(local_path, 'stdout.txt'), 'w+')
stderr_file = file(os.path.join(local_path, 'stderr.txt'), 'w+')

subprocess.call(["somecommand", "someparam"], stdout=stdout_file, stderr=stderr_file)
Run Code Online (Sandbox Code Playgroud)

这工作正常,并且正在创建具有相关输出的 txt 文件。然而,在忽略文件创建的内存中处理这些输出会更好。所以我使用 StringIO 包来处理它:

import subprocess
import StringIO

stdout_file = StringIO.StringIO()
stderr_file = StringIO.StringIO()

subprocess.call(["somecommand", "someparam"], stdout=stdout_file, stderr=stderr_file)
Run Code Online (Sandbox Code Playgroud)

但这不起作用。失败:

  File "./test.py", line 17, in <module>
    subprocess.call(["somecommand", "someparam"], stdout=stdout_file, stderr=stderr_file)
  File "/usr/lib/python2.7/subprocess.py", line 493, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 672, in __init__
    errread, errwrite) = self._get_handles(stdin, stdout, stderr)
  File "/usr/lib/python2.7/subprocess.py", line 1063, …
Run Code Online (Sandbox Code Playgroud)

python console file stringio

8
推荐指数
2
解决办法
3076
查看次数

在没有ImageMagick的情况下,使用PHP将PDF转换为图像

我有一个PHP站点,需要PDF到图像转换,我们显然使用imagemagick.但是,现在我们正在尝试迁移到不同的托管,似乎我将无法在新托管上安装imagemagick软件包来执行与现在相同的操作.

所以问题是 - 是否有任何方法可以使用纯PHP方法将PDF转换为图像,或者使用其他任何可以刚刚弹出到DOCUMENT_ROOT并且无需正确安装到系统中的方法.

这是一个Linux系统,但我不知道是什么发行版,我无法检查,因为我在这个系统中的权利真的有限.

谢谢Alex.

php linux pdf image imagemagick

5
推荐指数
1
解决办法
1万
查看次数

django-social-auth后端未找到

我正在尝试使用Twitter,GitHub,Google和Facebook添加身份验证django-social-auth,而我期望在那里提供的后端不可用.

根据手册安装:

AUTHENTICATION_BACKENDS = (
    'social_auth.backends.twitter.TwitterBackend',
    'social_auth.backends.contrib.github.GithubBackend',
    'social_auth.backends.facebook.FacebookBackend',
    'social_auth.backends.google.GoogleOAuthBackend',
    'social_auth.backends.google.GoogleOAuth2Backend',
    'social_auth.backends.google.GoogleBackend',
    # ....unnecessary backends

    'guardian.backends.ObjectPermissionBackend',
    'django.contrib.auth.backends.ModelBackend',
)

TWITTER_CONSUMER_KEY         = ''
TWITTER_CONSUMER_SECRET      = ''
FACEBOOK_APP_ID = ''
FACEBOOK_APP_SECRET = ''
GOOGLE_CONSUMER_KEY          = ''
GOOGLE_CONSUMER_SECRET       = ''
GOOGLE_OAUTH2_CLIENT_ID      = ''
GOOGLE_OAUTH2_CLIENT_SECRET  = ''

LOGIN_URL          = '/login/'
LOGIN_REDIRECT_URL = '/'
LOGIN_ERROR_URL    = '/login/'

SOCIAL_AUTH_FORCE_POST_DISCONNECT = True
SOCIAL_AUTH_FIELDS_STORED_IN_SESSION = ['next',]
Run Code Online (Sandbox Code Playgroud)

在模板中添加了URL:{% url socialauth_begin 'twitter' %}, {% url socialauth_begin 'github' %} etc在此之前一切正常.

但是当我点击链接时 - 它给了我错误: Incorrect authentication service "twitter"

根据手册,我检查了内容,social_auth.backends.BACKENDS …

django django-socialauth python-2.7

1
推荐指数
1
解决办法
3268
查看次数