在python 2.7.10,Mac OSX下使用mechanize进行SSLv3握手失败

时间:2015-09-23 08:06:19

标签: python ssl beautifulsoup handshake mechanize-python

我正在使用机械化进入网站。虽然能够在我朋友的计算机(其操作系统是Linux)上运行代码,但我面临以下握手失败警报:

CREATE OR REPLACE FUNCTION save_meta_data_test3()
  RETURNS text AS
$BODY$
DECLARE 
     section_seq integer;
     step_seq integer;
     rec_section   RECORD;
     rec_step RECORD;
     i integer;

     cur_section CURSOR 
         FOR select 
                     line_item->>'sectionName' as sectionName,line_item->>'sectionLabel' as sectionLabel,to_number(line_item->>'sectionOrder','99G999D9S') as sectionOrder,line_item->>'outOfScopeSection' as outOfScopeSection,
                     line_item->>'punchListSection' as punchListSection 
                from tbl d,
                         json_array_elements(d.j->'sectionElements') l,
                         json_array_elements(l->'sectionElement') AS line_item
               where tbl_id=3;

     cur_step CURSOR 
               FOR select 
                     line_item2->>'stepName' as stepName,line_item2->>'stepLabel' as stepLabel,to_number(line_item2->>'stepOrder','99G999D9S') as stepOrder,line_item2->>'questionLevelChange',
                     line_item2->>'punchListSection'
               from tbl d,
                        json_array_elements(d.j->'sectionElements') l,
                        json_array_elements(l->'sectionElement') AS line_item,
                        json_array_elements(line_item->'stepElements') AS line_item1,
                        json_array_elements(line_item1->'stepElement') AS line_item2
               where tbl_id=3 ;
BEGIN
 i:=0;
   -- Open the cursor
     OPEN cur_section;

      LOOP
    -- fetch row into the film

        raise notice '%', i;
        i:=i+1;
        FETCH cur_section INTO rec_section;
          raise notice 'section insert';
    -- build the output
          select nextval('checklist_section_id_seq') into section_seq;
          insert into Dummy_section_details(bfs_section_id,bfs_section_name,bfs_section_label,section_order) 
          values(section_seq,rec_section.sectionName,rec_section.sectionLabel,rec_section.sectionOrder);

        OPEN cur_step;
            LOOP
                 FETCH cur_step INTO rec_step;

                    raise notice 'step insert';
                select nextval('ckschema.checklist_step_id_seq') into step_seq;

                Insert into dummy_steps_details(bfs_step_id,bfs_step_name,bfs_step_label,bfs_section_id,step_order)
                    values(step_seq,rec_step.stepName,rec_step.stepLabel,section_seq,rec_step.stepOrder);

                    raise notice 'after step insert';

           EXIT WHEN NOT FOUND;  
        END LOOP;     
         -- LOOP

        CLOSE cur_step;
         raise notice 'after section insert';

     EXIT WHEN NOT FOUND;
   END LOOP;

   -- Close the cursor
   CLOSE cur_section;

   RETURN cur_section.sectionName;
END; $BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;

我使用以下代码:

urllib2.URLError: <urlopen error [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:590)>

1 个答案:

答案 0 :(得分:0)

默认情况下,SSLv3已被停用,因为它完全损坏。如果可能,请勿使用它。

  

注意:如果您发现当某些较旧的客户端或服务器尝试与此功能创建的SSLContext连接时,会收到错误消息,指出“协议或密码套件不匹配”,它可能只支持SSL3.0,此功能使用OP_NO_SSLv3排除。 SSL3.0被广泛认为是完全破碎的。如果您仍希望继续使用此功能但仍允许SSL 3.0连接,则可以使用以下命令重新启用它们:

ctx = ssl.create_default_context(Purpose.CLIENT_AUTH)
ctx.options &= ~ssl.OP_NO_SSLv3

这是第二个注释:https://docs.python.org/2/library/ssl.html#ssl.create_default_context

您需要以某种方式将配置的SSLContext传递给mechanize