根据要求更改instagram个人资料图片

时间:2019-04-25 12:20:03

标签: python instagram

我不擅长python,但我尝试使用python请求更改instagram个人资料图片 我使用此子代码。 :Python change instagram profile-picture with requests

我尝试将代码编辑为

import os
import requests

p_pic = "c:\my_new_pp.jpg"
p_pic_s = os.path.getsize("c:\my_new_pp.jpg")

headers = {
"Host": "www.instagram.com",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
"Accept": "*/*",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate, br",
"Referer": "https://www.instagram.com/f93w2s0u95/",
"X-CSRFToken": "My CSRFToken",
"X-Instagram-AJAX": "My AJAX",
"X-Requested-With": "XMLHttpRequest",
"Content-Length": str(p_pic_s),
"DNT": "1",
"Connection": "keep-alive",
"Cookie": "csrftoken=NQvE7wruxnmU3uzpb8Lifksf4dKFjk7H; mid=XLZKbQALAAGH4GarSPQx8glm5IC6; rur=FRC; ds_user_id=12896941070; sessionid=12896941070%3A3U9oQeVgj9UNIP%3A26"
}

url = "https://www.instagram.com/accounts/web_change_profile_picture/"

files = {'profile_pic': open(p_pic,'rb')}
values = {"Content-Disposition": "form-data", "name": "profile_pic", "filename":"profilepic.jpg",
"Content-Type": "image/jpeg"}

r = requests.post(url, files=files, data=values, headers=headers)
print(r.text)

我在命令窗口中得到的结果:

<!DOCTYPE html>
<html lang="en" class="no-js not-logged-in ">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">

        <title>
                  Page Not Found &bull; Instagram
                </title>


        <meta name="robots" content="noimageindex, noarchive">
        <meta name="mobile-web-app-capable" content="yes">
        <meta name="theme-color" content="#000000">
        <meta id="viewport" name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, viewport-fit=cover">
        <link rel="manifest" href="/data/manifest.json">





        <script type="text/javascript">
        (function() {
  var docElement = document.documentElement;
  var classRE = new RegExp('(^|\\s)no-js(\\s|$)');
  var className = docElement.className;
  docElement.className = className.replace(classRE, '$1js$2');
})();
</script>
        <script type="text/javascript">
(function() {
  if ('PerformanceObserver' in window && 'PerformancePaintTiming' in window) {
    window.__bufferedPerformance = [];
    var ob = new PerformanceObserver(function(e) {
      window.__bufferedPerformance.push.apply(window.__bufferedPerformance,e.getEntries());
    });
    ob.observe({entryTypes:['paint']});
  }

  window.__bufferedErrors = [];
  window.onerror = function(message, url, line, column, error) {
    window.__bufferedErrors.push({
      message: message,
      url: url,
      line: line,
      column: column,
      error: error
    });
    return false;
  };
  window.__initialData = {
    pending: true,
    waiting: []
  };
  function asyncFetchSharedData(extra) {
    var sharedDataReq = new XMLHttpRequest();
    sharedDataReq.onreadystatechange = function() {
          if (sharedDataReq.readyState === 4) {
            if(sharedDataReq.status === 200){
              var sharedData = JSON.parse(sharedDataReq.responseText);
              window.__initialDataLoaded(sharedData, extra);
            }
          }
        }
    sharedDataReq.open('GET', '/data/shared_data/', true);
    sharedDataReq.send(null);
  }
  window.__initialDataLoadFromCache = function(sharedData) {
    var extra = { entry_data: sharedData.entry_data };
    try {
      var cachedSharedData = localStorage.getItem("ig_sdc");
      if (!cachedSharedData) {
        throw new Error();
      }
      cachedSharedData = JSON.parse(cachedSharedData);
      if (cachedSharedData.expiry < Date.now() || cachedSharedData.schemaVersion != sharedData.cache_schema_version) {
        throw new Error();
      }
    } catch (ex) {
      return asyncFetchSharedData(extra);
    }
    window.__initialDataLoaded(sharedData, cachedSharedData.data);
  };

  function notifyLoaded(item, data) { .....................etc

但个人资料图片未更改。 代码中的错误在哪里?请帮助

0 个答案:

没有答案