{"id":1127,"date":"2023-08-30T12:43:11","date_gmt":"2023-08-30T10:43:11","guid":{"rendered":"https:\/\/inseri.swiss\/?p=1127"},"modified":"2024-11-11T12:43:11","modified_gmt":"2024-11-11T12:43:11","slug":"python-and-requests","status":"publish","type":"post","link":"https:\/\/zi.uzh.ch\/whp\/science-it\/inseri\/2023\/08\/python-and-requests\/","title":{"rendered":"Python and Requests Package"},"content":{"rendered":"\n<p>Our Python code block relies on <a href=\"https:\/\/pyodide.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">Pyodide<\/a>, a Python distribution that used to not support the <code>requests<\/code> package (inseri core &lt; 0.3.5). But now we can easily use the <code>requests<\/code> package. If you use an older older version, please update.<\/p>\n\n\n\n<div class=\"wp-block-inseri-core-python\" data-attributes=\"{&quot;autoTrigger&quot;:false,&quot;blockId&quot;:&quot;8SFlAlLlkjd7uZxQ4OAAE&quot;,&quot;content&quot;:&quot;import%20requests%0A%0Aurl_text%20%3D%20%22https%3A%2F%2Fraw.githubusercontent.com%2Finseri-swiss%2Finseri-core-wp%2Fmain%2FLICENSE%22%0Aresponse%20%3D%20requests.get(url_text)%0Aresponse_text%20%3D%20response.text%0A%0Aurl_image%20%3D%20%22https%3A%2F%2Fraw.githubusercontent.com%2Finseri-swiss%2Finseri-core-wp%2Fmain%2F.wordpress-org%2Fbanner-1544x500.jpg%22%0Aresponse%20%3D%20requests.get(url_image)%0Aresponse_image%20%3D%20response.content&quot;,&quot;editable&quot;:false,&quot;height&quot;:286,&quot;inputCode&quot;:&quot;&quot;,&quot;inputs&quot;:{},&quot;isVisible&quot;:true,&quot;label&quot;:&quot;Click Run to fetch the text and the image&quot;,&quot;metadata&quot;:{&quot;name&quot;:&quot;python-requests&quot;},&quot;mode&quot;:&quot;editor&quot;,&quot;outputs&quot;:[[&quot;response_text&quot;,&quot;text\/plain&quot;],[&quot;response_image&quot;,&quot;image\/jpeg&quot;]]}\">is loading &#8230;<\/div>\n\n\n\n<p>Next we will display the text and the image using the Text Viewer block and the Image Box block, respectively.<\/p>\n\n\n\n<div class=\"wp-block-inseri-core-text-viewer\" data-attributes=\"{&quot;blockId&quot;:&quot;8iZ8Wuxrsx6XCgbp37oUG&quot;,&quot;content&quot;:&quot;&quot;,&quot;height&quot;:150,&quot;inputKey&quot;:&quot;8SFlAlLlkjd7uZxQ4OAAE\/response_text&quot;,&quot;label&quot;:&quot;&quot;,&quot;metadata&quot;:{&quot;name&quot;:&quot;textViewer-request&quot;}}\">is loading &#8230;<\/div>\n\n\n\n<div class=\"wp-block-inseri-core-image\" data-attributes=\"{&quot;altText&quot;:&quot;&quot;,&quot;blockId&quot;:&quot;xNCSs4GIxJ8OOoliejoaY&quot;,&quot;caption&quot;:&quot;&quot;,&quot;fit&quot;:&quot;contain&quot;,&quot;height&quot;:null,&quot;inputKey&quot;:&quot;8SFlAlLlkjd7uZxQ4OAAE\/response_image&quot;,&quot;metadata&quot;:{&quot;name&quot;:&quot;image-request&quot;}}\">is loading &#8230;<\/div>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:60%\"><\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-inseri-core-export alignright\" data-attributes=\"{&quot;align&quot;:&quot;right&quot;,&quot;blockId&quot;:&quot;vaxQQCzmrnvQCf4meQgfk&quot;,&quot;metadata&quot;:{&quot;name&quot;:&quot;export&quot;},&quot;postId&quot;:1127}\">is loading &#8230;<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Our Python code block relies on Pyodide, a Python distribution that used to not support the requests package (inseri core &lt; 0.3.5). But now we can easily use the requests package. If you use an older older version, please update. Next we will display the text and the image using the Text Viewer block and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[40,43,48,53],"class_list":["post-1127","post","type-post","status-publish","format-standard","hentry","category-basic-example","tag-export","tag-image-box","tag-python-code","tag-text-viewer"],"_links":{"self":[{"href":"https:\/\/zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/posts\/1127","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/comments?post=1127"}],"version-history":[{"count":1,"href":"https:\/\/zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/posts\/1127\/revisions"}],"predecessor-version":[{"id":2122,"href":"https:\/\/zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/posts\/1127\/revisions\/2122"}],"wp:attachment":[{"href":"https:\/\/zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/media?parent=1127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/categories?post=1127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zi.uzh.ch\/whp\/science-it\/inseri\/wp-json\/wp\/v2\/tags?post=1127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}