无法使用文件向其他php网站发出POST请求

无法使用文件向其他php网站发出POST请求,php,request,python-3.5,urllib2,Php,Request,Python 3.5,Urllib2,最近,我已经将我的应用程序从python2/pylons迁移到python3/pyramid 在我的plyons应用程序中,我使用以下代码向第三方php网站(也由我维护)发出POST请求 上面的代码工作得非常好。但是在python3上,poster不受支持,我不能使用我甚至不知道该做什么的register\u openers() 在python3中,我使用请求模块 import requests from requests_toolbelt import MultipartEnc

最近,我已经将我的应用程序从python2/pylons迁移到python3/pyramid

在我的plyons应用程序中,我使用以下代码向第三方php网站(也由我维护)发出POST请求

上面的代码工作得非常好。但是在python3上,poster不受支持,我不能使用我甚至不知道该做什么的
register\u openers()

在python3中,我使用请求模块

import requests
        from requests_toolbelt import MultipartEncoder
        url = config['php_website_url']
        m = MultipartEncoder(
                fields={'biosamples_metadata': open(file_bs_md, 'rb'),
                        "metastore":open(file_ds_md, "rb"),
                        "annotation-submit":  "Validate Annotation Files"
                        }
                )
        request = requests.post(url, data=m)
        return_text = request.text
但是,此代码不能正常工作。它转到php应用程序并执行当您收到请求时应该执行的代码部分

下面是php代码的样子

      public function handle_request () {

            $TEMPLATE = 'content_main';

            // Process POST
            if ($this->isPOST()) {
                  $this->_annotationFiles = array();
                   return $this->error_span('This is Get');
                 } 
            else ($this->isGET()) {
                  $this->_annotationFiles = array();
                  return $this->error_span('This is Post')
                 } 

感谢您的帮助

我不确定您的PHP代码,但以下是使用Python 3和请求将文件和数据发布到远程url的正确方法:

导入请求
邮政地址=”https://example.com/post_url"
数据={
‘foo’:‘bar’,
“foo_a”:“bar_a”:
}
文件={'file':打开('report.xls','rb')}
r=requests.post(post\u addr,data=data,files=files)

已编辑的问题
      public function handle_request () {

            $TEMPLATE = 'content_main';

            // Process POST
            if ($this->isPOST()) {
                  $this->_annotationFiles = array();
                   return $this->error_span('This is Get');
                 } 
            else ($this->isGET()) {
                  $this->_annotationFiles = array();
                  return $this->error_span('This is Post')
                 }