Everything works fine when I use the link (https://docs.google.com/spreadsheet/ccc?key=XXXXXXXXX&output=csv) in the browser. Why I always get an error using this script:
import requests
response = requests.get("https://docs.google.com/spreadsheet/ccc?key=XXXXXXXXX&output=csv")
print(response.content)
b'Error 400 (Bad Request)!!1{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{color:#222;text-align:unset;margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px;} > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}pre{white-space:pre-wrap;}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
400. That\xe2\x80\x99s an error.
The server cannot process the request because it is malformed. It should not be retried. That\xe2\x80\x99s all we know.'
CodePudding user response:
That link is working fine in your browser because ur gmail account is logged in in your browser. And not all websites accept requests from python libraries so you better should find more reliable options and check for the compatibility by trail and error for it to know whether it works or not.
follow this link for accomplishing your inttending task spread_sheet using python
this link mentions methods without using google api but just by pandas pandas procedure
CodePudding user response:
The problem you're having is that you are trying to access the URL for the webpage that allows users to access the document through the browser, even though you're connecting as an application. This will present you with a variety of issues. Instead, you should try using the Google Docs API, here, or else the Google Sheets API, here.
